Hi everyone, is it very common when we start coding to create objects that needs others objects to work e.g. in a Car class that need a Person object to start the engine and drives ( starEngine and drive are hypothetical methods that needs a Person instance). So we can say that a Car needs a Person to work.https://medium.com/media/fc60e8d54ac0bebd703d00771d4446e4/hrefThe code above shows us that Jhon is driving our car, and only Jhon can do it! Because every Car object will create an instance of a Person named Jhon. But what if Mary wants to drive? How can we rewrite that code to let Mary drive our car?https://medium.com/media/c827bfd5dc2aafee4e36f31af205caad/hrefWe can pass a Person to our Car, making it work for any instance of Person, in other words: reusable.


I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too.

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.


This article is related to

xcode,dependency-injection,swift,unit-testing