The Object-Oriented Design Principles will be the core of OOP programming, but I have seen most of the Java programmers chasing design patterns like Singleton pattern, Decorator pattern, or Observer pattern, and not putting enough attention on learning Object-oriented analysis and design.
It’s vital that you learn the basics of Object-oriented programming like Abstraction, Encapsulation, Polymorphism, and Inheritance. But, simultaneously, it’s equally important to know object-oriented design principles.
They will allow you to create a clean and modular design, which will be easy to test, debug, and keep maintaining in the future.
I’ve regularly seen Java programmers and developers of varied experience level, who have either never found out about these OOP and SOLID design principle, or simply doesn’t know what benefits a specific design principle offers and how to apply these design principle in coding.
To accomplish my part, I’ve jotted down all important object-oriented design principles and putting it here for quick reference. These will at least give you some idea in what they are and what benefit they offer.
I have not put examples, just to keep carefully the article short but you can find a large amount of examples of these design principles on the internet and even on my Java blog, just utilize the search bar near the top of the page.
If you are not able to understand a design principle, you should try to do several example because sometimes we hook up to another example or author better nevertheless, you must understand these design principles and discover how to make make use of it in your code.
Another thing that can be done is to join a thorough object-oriented design course like SOLID Principles of Object-Oriented Design by Steve Smith on Pluralsight. It has helped me a whole lot in my understanding and application of the principles.
Btw, I’ve shared some relevant and useful courses and books occasionally, both free and paid, and I will earn some money in the event that you buy something which isn’t free.
They are also a number of the resources I’ve used to understand SOLID design principles and Programming on the whole and nice for learning a few of these principles in depth.
10 Object Oriented and SOLID Desing Principles for Programmers
Though the easiest way of learning any design principle or pattern is a real-world example and understanding the consequences of violating that design principle, subject of the article is Introducing Object-oriented design principles for Java Programmers, who are either not exposed to it or in the training phase.
I personally think each one of these OOP and SOLID design principles needs articles to make clear them clearly, and I will surely try to do this here, but also for now, just get yourself ready for a quick bike ride on design principle town 🙂
- DRY (Don’t repeat yourself)
Our first object-oriented design principle is DRY, as the name suggests DRY (don’t repeat yourself) means don’t write duplicate code, instead use Abstraction to abstract common things in one place.
Assuming you have a block of code in a lot more than two places consider which makes it another method, or if you are using a hard-coded value more than one time make them public final constant. The benefit for this Object oriented design principle is in maintenance.