Professional Documents
Culture Documents
• Solid Principles are the design principles that enable us manage most
of the software design problems
• SOLID Acronym
This means that every module or class should have responsibility over a
single part of the functionality provided by the software and that
responsibility should be entirely encapsulated by the class
• There can be many members in the class as long as they related to the
single responsibility
Problem:
interface Iuser
{
bool Login(string username,string password);
bool Register(string username,string password,string email);
bool LogError(string error);
bool SendEmail(string emailContent);
}
In this interface we can see that the methods LogError and SendEmail doesn’t
have same functionality that a user is provided with so they should have a
separate interface A user is only related with the Login and Register method
the functionality of LogError And SendEmail is not directly related to the user
So according to the single responsibility principle
Solution:
interface Iuser
{
bool Login(string username,string password);
bool Register(string username,string password,string email);
}
interface Ilogger
{
bool LogError(string error);
}
interface Iemail
{
bool SendEmail(string emailContent);
}
OPEN CLOSED PRINCIPLE
If Not followed
public Employee(){
}
• New derived classes just extend without replacing the functionality of old
classes
In the previous example that we used in OCP ,now we want add a new
employee category that is contractEmployee the contract employee will not get
the bonus and we want to display the minimum salary of
three(Temperory,Permanent and contract employee) now we will make
interfaces for get the Minimum salary and for Calculating the bonus .Contract
Employee will not implement the Calculate bonus interface
Interface IEmployeeBonus
{
decimal CalculateBonus(decimal salary);
}
Interface IEmployee
{
int ID{ get; set;}
string Name { get; set; }
decimal GetMinimumSalary();
}
Public class PermanentEmployee: IEmployeeBonus, IEmployee
{
public PermanentEmployee()
{ }
Since all the printers cannot perform all these tasks .So we will apply
interface segregation Principle for common printers and then separate
interfaces for expensive and most expensive printers so according printers
can choose interfaces relevant to it.
Solution:
This means that the interaction between high level and low level modules
should be thought of as an abstract interaction between them
Problem:
public classBusinessLogicLayer
{
private readonly DataAccessLayer DAL;
public BusinessLogicLayer()
{
DAL = new DataAccessLayer();
}
public void Save(Object details){ //perform save}
}
Data Access
Layer
References
Repository
Interface inherits
public classBusinessLogicLayer
{
private readonly IRepository Layer DAL;
public BusinessLogicLayer(IRepositoryLayer repositoryLayer )
{
DAL = new DataAccessLayer();
}
public void Save(Object details){ //perform save}
}
• End up with tight or strong coupling of the code with many other
modules/applications
• Reusability