Being a Software Developer or a Software Architect you must think what end product you are giving to your client; and to provide a good product our design must be SOLID.
Lets see what happens if our design is not good
Below picture looks funny but, its a perfect example of bad design, and I really don't need to write consequences of having such design :)

This is what can happen if you do not care about design of your software.
To avoid such design, people had come up few principles that is called as SOLID Design principles.
Now let see what are those.
Lets see what happens if our design is not good
Below picture looks funny but, its a perfect example of bad design, and I really don't need to write consequences of having such design :)

This is what can happen if you do not care about design of your software.
To avoid such design, people had come up few principles that is called as SOLID Design principles.
Now let see what are those.
1. Single Responsibility Principle:-
What this principle says is give one and only one responsibility to a "module" or "class" or "function". Therefor in future if at all you want to remove that function or you want to make any changes to function it will NOT affect any other functionality of entire system. Same is applicable for module or class as well.
Now lets see how could be bad design in programmatic way
Objective:- after user login display following statistics
- count of all jobseekers
- count of all employers
- count of all active jobs
public void login(String username, String password){
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=ABC");
java.sql.Statement st= con.createStatement();
boolean isCorrect = false;
//check for login
rs=st.executeQuery("select userName, pass from login_tbl where userName='"+username+"' and pass='"+password+"'");
while(rs.next()) {
isCorrect =true;
}
if(isCorrect){
//fetch count of all employers
rs=st.executeQuery("select count(*)employer from employer_com");
while(rs.next()) {
dbemployer=rs.getString("employer");
}
//fetch count of all jobseekers
rs=st.executeQuery("select count(*)jobseeker from resume_rsm");
while(rs.next()) {
dbjobseeker=rs.getString("jobseeker");
System.out.println("no of employer is"+dbjobseeker);
}
//fetch count of all all active jobs
rs=st.executeQuery("select count(*)Active from job_job1 where job_deadline>='"+systdate+"'");
while(rs.next()) {
dbactive=rs.getString("Active");
System.out.println("no of Active jobs is"+dbactive);
}
}
}catch(Exception e){
}
}
In above code to achieve the objective I have wrote all my business logic in single function itself.
Now suppose requirement has got changed "Instead of after login, display above statistics after click on my profile except active jobs".
Now what will you do? If you have such code written, I guess you have re-write your code.
So it is always advised to have single responsibility for one function/class.
In above code you can have separate functions for each and every part of your objective.
Like have functions
Now suppose requirement has got changed "Instead of after login, display above statistics after click on my profile except active jobs".
Now what will you do? If you have such code written, I guess you have re-write your code.
So it is always advised to have single responsibility for one function/class.
In above code you can have separate functions for each and every part of your objective.
Like have functions
- dataBaseConnection() -- to connect database
- login() -- to check login business login
- jobSeekerCount() -- count of all jobseekers
- employersCount() -- count of all employers
- activeJobCount() -- count of all active jobs
1. Open and Closed Principle:-
Our code must be open for extension but should be closed for any modification.
Now what is that mean?
Now what is that mean?
Let me describe it using following picture.