loading...
Cover image for Composition over Inheritance [example in PHP]

Composition over Inheritance [example in PHP]

anastasionico profile image anastasionico ・2 min read

Let me ask you a few direct questions:

Did you ever come back after a year to an old application to add new features?
Have you ever fall in the trap of creating too many relationships among your classes and not remember why?
Have you ever had a manager or client that asked you to refactor some code with crazy functionalities?

If you've experienced any of these scenarios or wish to avoid them in the future, read this post:

Why favor Composition over Inheritance [example in PHP]?

Click here to read it now.

Trevor is a South African freelance web-developer, he has been doing for a while and his clients love him.

He, like all of us, is very happy to work on amazing projects and make business owners of his town satisfied.

He is having the time of is life.

Until that client came back and wanted Trevor to update the web application he worked on a year before.

The web application works just fine, the issue is that it was designed only to do specific tasks, and now the business owner decided that he wants more features, manage more data, and sell more products.

I, Trevor and, I am sure, you have already lived this nightmare, or you will experience it soon.

The needs to edit some code, adding conditions where they were not supposed to be, adding inheritances here and there and more.

Write scalable and reliable code that requires low maintenance and do not need to be discombobulated every time there is an update is a duty of every web developer, but it is also fun to work with and a pleasure to preserve

In this post, you are going to see how to do so, learning the concept of composition and how you can avoid complicating your classes

Read the full post here

Discussion

pic
Editor guide