DEV Community

Cover image for Composition over Inheritance [example in PHP]
anastasionico
anastasionico

Posted on

1

Composition over Inheritance [example in PHP]

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

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (0)

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

👋 Kindness is contagious

DEV shines when you're signed in, unlocking a customized experience with features like dark mode!

Okay