Thursday, 18 February 2016

5 Class Design Principles in Java

The 5 Class Design Principles

S.O.L.I.D is the acronym for five basic principles of object-oriented programming to design a class.

Single responsibility
Liskov substitution
Interface segregation and
Dependency inversion.

S.O.L.I.D principles help us to create a system that is easy to maintain and extend over time. Well designed and written classes can speed up the coding process by leaps and bounds, while reducing the number of bugs in comparison.

Classes are the building blocks of System. If these blocks are not strong, your building (i.e. System) is going to face the tough time in future.

If Classes are not so well-written, can lead to very difficult situations when the application scope goes up or application faces certain design issues either in production or maintenance.

It is part of an overall strategy of agile and Adaptive Software Development.

Single responsibility principle
“a class should have only a single responsibility” (i.e. only one potential change in the software's specification should be able to affect the specification of the class)
Open/closed principle
“software entities … should be open for extension, but closed for modification.”

Liskov substitution principle

“objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program.”

Interface segregation principle

“many client-specific interfaces are better than one general-purpose interface.”
Dependency inversion principle

one should “Depend upon Abstractions. Do not depend upon concretions.”

Introduced by Michael Feathers for the "first five principles" named by Robert C. Martin in the early 2000s.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...