Principles of Class Design (SOLID)
SRP:
Single Responsibility Principle
– An
object should have only a single responsibility & all the responsibility
should be entirely encapsulated by the class.
– There
should never be more than one reason for a class to change
OCP:
Open/Closed Principle
– Software
entities should be open for extension, but closed for modification
LSP:
Liskov Substitution Principle
– Objects
in a program should be replaceable with instances of their subtypes without
altering the correctness of that program
ISP:
Interface Segregation Principle
– many
client specific interfaces are better than one general purpose interface
– Once an
interface has gotten too 'LARGE' split it into smaller and more specific
interfaces. So that, any clients of the interface will only know about the
methods that pertain to them. No client should be forced to depend on methods
it does not use
DIP:
Dependency Inversion Principle
– Depend
upon Abstractions. Do not depend upon concretions.
– Dependency
Injection (DI) is one method of following this principle.
Class Relationship:
•
Dependency
Weaker form of relationship which
indicates that, one class depends on another because, it uses it at some point
of time.
Dependency exists, if a class is a
parameter variable or local variable of a method of another class.
•
Association
Loose form of relationship (Student
can enroll in multiple Courses, and A Course can have multiple Students)
•
Aggregation
Whole part relationship. Part can
exist without Whole. (Engine can exist even if Car is destroyed, the same
Engine could be used in a different Car)
•
Composition
Stronger form of whole part
relationship. Part cannot exist without Whole. (OrderDetail cannot exist if
Order is deleted. If Order is deleted, OrderDetail also gets deleted)
•
Generalization
/ Inheritance
Comments
Post a Comment