When it comes to OO designing, it is a good idea to have a strategy to follow.
A strategy allows you to think and organize ideas in a particular fashion that is comfortable to you.
I’ve found SOLID principle easy enough for beginners and experts to understand and practice.
This was originally put forward by Rober C. Martin, who is a pioneer in agile software development and extreme programming.
Checkout Cleancoders to know more.
Chances are, you may be already using SOLID principle, just without giving it a name.
S - Single Responsibility Principle (SRP)
O - Open/Closed Principle (OCP)
L - Liskov Substitution Principle (LSP)
I - Interface Segregation Principle (ISP)
D - Dependency Inversion Principle (DIP)
Thats right, SOLID stands for a bunch of other acronyms.
The single responsibility principle states that every class should
have a single responsibility, and that responsibility should be
entirely encapsulated by the class. All its services should be
narrowly aligned with that responsibility.
Fairly simple. A Student class should manipulate Student properties and not the the properties of School. Specification of the class remains mostly untouched unless there is a big change in requirement of your software.
It is good to keep in mind that, there can be some exceptions to this. For example a utility class may provide methods for managing both Students and Schools.
Software entities should be open for extension, but closed for modification.
The idea is that once a class is implemented completely, it should not be modified for including new features. Bugs and error correction must be done as and when required. Adding a new feature will require new specification and release of newer version.
Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program. See also design by contract.
That right there is the basic use of Dependency Injection, right? You define a parent interface and replace them by concrete implementation which are derivatives.
Many client-specific interfaces are better than one general-purpose interface.
Interfaces provide abstraction no implementation. When developing client interfaces, it should be kept at minimum and should only expose those methods which are essential for that client.
##D - Dependency Inversion Principle (DIP)
One should “Depend upon Abstractions. Do not depend upon concretions.”
Dependency injection is one method of following this principle.