Professional Documents
Culture Documents
ASD Lab Practical
ASD Lab Practical
SOLID Principles—
What does the SOLID principles actually means? Well, it’s just an
acronym of the five principles listed as below.
S - Single Responsibility Principle (known as SRP)
O- Open/Closed Principle
L - Liskov’s Substitution Principle
I - Interface Segregation Principle
D - Dependency Inversion Principle
The name itself suggest that the “class should be having one and only one
responsibility”. What does it mean? Well let’s take the class A which does the
following operations.
Open a database connection
Fetch data from database
Write the data in an external file
The issue with this class is that it handles lot of operations. Suppose any of the
following change happens in future.
New database
Adopt ORM to manage queries on database
Change in the output structure
So in all the cases the above class would be changed. Which might affect the
implementation of the other two operations as well. So ideally according to SRP there
should be three classes each having the single responsibility.
code:
#include<bits/stdc++.h>
using namespace std;
class User{
public:
bool Login(string username,string password){
cout<<username<<" "<<password<<endl;
cout<<"Login Successfully\n";
return true;
}
class Error{
public:
class Email{
public:
int main(){
User *us=new User();
us->Login("Dhruv kumar","198038");
Output:
Dhruv kumar 198038
Login Successfully
Error!! Please try again
Sent Email
Open Closed Principle:
This principle suggests that “classes should be open for extension but closed
for modification”.
What is means is that if the class A is written by the developer AA, and if the
developer BB wants some modification on that then developer BB should be
easily do that by extending class A, but not by modifying class A.
The principle states that software entities like class, modules, functions, etc.;
should be able to extend a class behaviour without modifying it.
This principle separates the existing code from modified mode to provide
better stability, maintainability and minimizes the changes in the code.
In a nutshell, the developer must need to change only a specific part of the
code (a class or a function) every time a requirement changes.
Code:
include<iostream>
using namespace std;
class Rectangle{
public:
int length,breadth;
Rectangle(int l,int b){
length=l;
breadth=b;
}
int area(){
return length*breadth;
}
};
class Square{
public:
int side;
Square(int s){
side=s;
}
int area(){
return side*side;
}
};
int main(){
Rectangle *r=new Rectangle(3,4);
cout<<"Area of rectangle is "<<r->area()<<endl;
Output:
Area of rectangle is 12
Area of square is 25
Code:
#include<iostream>
using namespace std;
class Shape{
public:
void area(){
cout<<"Area";
}
};
int main(){
Rectangle *r=new Rectangle(3,4);
cout<<"Area of rectangle is "<<r->area()<<endl;
Output:
Area of rectangle is 12
Area of square is 25
The Interface Segregation Principle states that clients should not be forced to
implement interfaces they don't use.
Basically, the principle is similar to the SINGLE RESPONSIBILITY
PRINCIPLE in the sense that classes should only implement methods that
they actually use.
This principle suggests that “many client specific interfaces are better than one
general interface”.
This is the first principle which is applied on interface, all the above three
principles applies on classes.
As with all SOLID principles, ISP contributes to making code more
manageable and robust.
This is particularly in the case where a change has to be made to an interface
which is propagated downwards to all subclasses implementing it.
Without ISP, the function being updated would have to be updated in the
subclasses too even though they don’t implement any business logic.
Code:
#include <bits/stdc++.h>
using namespace std;
class vehicle{
public:
string color;
int price;
void setprice(int price)
{
cout<<"Setting price to "<<price<<endl;
this->price = price;
}
void setcolor(string col)
{
cout<<"Setting color to "<<col<<endl;
color = col;
}
int main()
{
car car1;
car1.setcolor("Blue");
car1.setprice(5000000);
car1.start();
car1.speed();
car1.horn();
cout<<endl;
plane plane1;
plane1.setcolor("White");
plane1.setprice(1000000000);
plane1.start();
plane1.speed();
plane1.land();
return 0;
}
Output:
Setting color to Blue
Setting price to 5000000
Starting Car
Speeding Car
Pressing the horn
Code:
#include<bits/stdc++.h>
using namespace std;
class Manager{
public:
vector<Employee*> employees;
void addemployee(Employee *e1)
{
employees.push_back(e1);
}
};
int main()
{
Manager m1;
m1.employees.push_back(new Developer());
m1.employees.push_back(new Designer());
m1.employees.push_back(new Tester());
cout<<endl;
m1.employees[0]->Work();
m1.employees[1]->Work();
m1.employees[2]->Work();
return 0;
}
Output:
Developer added
Designer added
Tester added
USER STORIES
User story is the smallest unit of work in an agile framework. It’s an end goal,
not a feature, expressed from the software user’s perspective.
A user story is an informal, general explanation of a software feature written
from the perspective of the end user or customer.
The purpose of a user story is to articulate how a piece of work will deliver a
particular value back to the customer. Note that "customers" don't have to be
external end users in the traditional sense, they can also be internal
customers or colleagues within your organization who depend on your team.
Risk management and Testing:
UNIT TESTING is a type of software testing where individual units or
components of a software are tested. The purpose is to validate that each
unit of the software code performs as expected. Unit Testing is done
during the development (coding phase) of an application by the
developers. Unit Tests isolate a section of code and verify its correctness.
A unit may be an individual function, method, procedure, module, or
object.
o Invalid user type
o Invalid discount amount
o Can’t edit discount (read only mode).
o Cannot miss date (must attempt)
Jira Software is a powerful platform that combines issue collection and agile project
management capabilities into a single application. Using Jira Software helps you plan
and organize tasks, workflows, and reports for your agile team more efficiently.