Object-Oriented Design for Easy Future Changes
Object-oriented design aims to arrange dependencies to allow for easy future change. The critical thing here is experimentation. We don’t want to make a decision forced by the tools we are using or by the pressure that’s not necessary. There should be no code in your apps for anticipatory reasons. You cannot guess the future. You will always be wrong, and when you add complexity to the present to do something you think will live in the future, it will always cost you money. Object-Oriented Design’s goal is flexibility. Follow its principles when there’s a business need to be resolved. The cost of any change should be proportional to the benefits the difference achieves.
Objects in the system can be composed in different ways depending on the context. I know my API, and I see the API, so I can plug and play all the objects I interact with anywhere they’re coupled. It’s used system-wide context-independent; if you wrote the behavior, I only need part of the world to be a sure way to work.
Loosely coupled objects promote independent context between components. Loosely coupled objects need more knowledge about the environment or dependencies. The objects define the role that different implementations can play. Loosely coupled classes are not bound together. It is possible to substitute across the boundary of whoever plays the role. Manage dependencies by injection to promote composing objects in runtime. e.g., swapping the implementation to use data from a service.
TRUE codes are guidelines that aim to enforce specific properties of good Object-Oriented code. Is the code transparent? Transparent code exposes what can be affected and how it will be affected when we change. Reasonable code exists because it brings more benefits to the business operation than the cost of writing it. Is the code usable? Can we reuse the code in a different context? Is the code flexible enough? Is the code Exemplary? Easy to follow after reading it?
Existing code should be usable in new and unexpected contexts. The code itself should encourage those who change it to perpetuate these qualities. Few difficult-to-change applications are pleasant to work on. Object-oriented Design is about managing dependencies. It is a coding technique set that arranges dependencies so objects can tolerate change. Object-Oriented Design emphasizes flexibility rather than perfection. Object-Oriented Design is not in the business of acquiring perfection but in the business of flexibility. Tolerance of the ambiguity of a class of an object is the hallmark of a confident designer.
[¹]: Practical Object-Oriented Design: An Agile Primer Using Ruby