paint-brush
Why You Should Use Class Delegation In Kotlinby@CodyEngel
1,340 reads
1,340 reads

Why You Should Use Class Delegation In Kotlin

by Cody Engel5mDecember 2nd, 2018
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

In most traditional programming languages code reuse typically comes in the form of inheritance. I’ve been on many projects where the innocent BaseThingy quickly turns into DoesEveryThingy in just a few short months because unfortunately inheritance wasn’t meant for code reuse in ways we often hope for. You see, well designed systems are often constructed from smaller objects that do one thing well and leave everything else to others. The problem is sometimes we have classes that require management of other smaller objects, we can call these classes Controllers as their job is to control other classes. It can be tempting to create a BaseController which will handle things like thread pool management, instantiating different views, injecting models, etc. The downside to this approach comes when you have a lot of child controllers relying on the base implementation except they need to manage the thread pool slightly differently or maybe you want to inject the models using a different approach, or maybe you only need one part of the base class and nothing more. There has to be a better way, this is where the idea of <a href="https://robots.thoughtbot.com/reusable-oo-composition-vs-inheritance">composition over inheritance</a> comes into&nbsp;play.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Why You Should Use Class Delegation In Kotlin
Cody Engel HackerNoon profile picture
Cody Engel

Cody Engel

@CodyEngel

L O A D I N G
. . . comments & more!

About Author

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite