CS603P - All Lab Manuals (Lab 1 To 16)
CS603P - All Lab Manuals (Lab 1 To 16)
6 Design Pattern 13
8 Learn to overcome the issue of ‘Bad Code smell’ through Refactoring with 23
Extract Method Technique
11 Quality Attributes 36
13 Architectural Patterns 42
Initial starting cost of the project according to group A and B point of view
Extendable design and maintenance cost according to group A and B point of view
Feature addition cost according to group A and B point of view
Reduce complexity
Solution
In above scenario, group B is on right direction because Techno should give due time to the requirement
engineering process and, design and architecture.
Initially, the cost of group A scenario is less then group B, because a software project required good amount
of time as well as human effort to gather requirements, analyze these requirements then prepare design
document. Software designer prepare design considering different angles like, requirements may change in
the future so design should welcome the change in design and system, SIMCO may demand more features
to add in future so design should be extendable. Software may require maintenance so software should be
easy to understand to maintain.
While if a company do not give good amount of time towards documentation then it is true that company
may save good time and money but later SIMCO’s budget will increase a lot to maintain and adding more
features.
If a project has zero or less documentation then it will be hard to understand the system so if a project is
hard to understand then it is true that it will be hard to extend, maintain and hard to add more features.
Because hard to understand means it is complex so a good documentation always reduce complexity,
welcome changes and maintenance but required spending good amount of time and money upfront. So It is
up to the SIMCO, either SIMCO pay now or pay later.
Lab Manual- 02
Topic: Identification of objects and actors from a case study
Case Study:
The hospital’s manager inputs the patient’s name, date of birth, address and
emergency contact into the system along with the persons’ health insurance
numbers. A patient may have multiple health insurances (from different companies).
All health insurance numbers are entered along with details of each company. The
system then verifies the insurance credentials from the corresponding company.
Upon successful validation, the patient is registered with the hospital.
Question
You are required to find the objects and the actors in the above case study.
Solution:
Actors:
Objects:
Patient
Manager
Insurance company
Registration
Lab Manual- 03
Topic: Class classification and relationships
Problem Statement
You are familiar with the Jet-Plane, Bicycle, Rowing-Boat, Train, Glider, Car, Ferry, Yacht and
truck. You are required classify these classes into relevant groups and create class hierarchy.
Solution:
Classification
Relationship hierarchy:
Lab Manual- 04
Lab Title: Write a C++ program to implement single inheritance.
Objectives: Learn how to develop single inheritance in the C++ programming language.
Tool: C++
Program:
#include<iostream.h>
class teacher
{
private:
char name[30];
long number;
public:
void getdata()
{
cout<<”\n \t Provide Full name:”;
cin>>full name;
cout<<”\n \t Provide id number:”;
cin>>id number;
}
void putdata()
{
cout<<”\n \t full name:”<<Full name;
cout<<”\n \t id number : ”<<id number;
}
};
class student : public teacher
{
private:
int mk1,mk2,mk3,mk4;
public:
void getdata()
{
teacher :: getdata();
cout<<”\n \t Provide four subjects marks:”;
cin>>mk1>>mk2>>mk3>>mk4;
}
void putdata()
{
teacher :: putdata();
cout<<”\n \t Four subjects marks:”<<mk1<<mk2<<mk3>>mk4;
}
};
void main()
{
student sb1,sb2,sb3,sb4;
cout<<”\n Provide student1 information :\n”:
sb1.getdata();
cout<<”\n Provide student2 information :\n”;l
sb2.getdata();
cout<<”\n Provide student3 information :\n”;2
sb3.getdata();
cout<<”\n student 1 information:”;
sb1.putdata();
cout<<”\n student 2 information:”;
sb2.putdata();
cout<<”\n student 3 information:”;
sb3.putdata();
Output:
Provide student1 information
Provide full name: Haroon Ali
Provide id number:4
Provide 4 subject marks:80 75 95 88
Provide student 2 information
Provide full name: Ayesha Ali
Provide id number:6
Provide 4 subjects marks :75 95 65 77
Provide student 3 information
Provide full name: Ehsan Ali
Provide id number:8
Provide 4 subjects marks:55 98 84 90
Student 1 information
Full Name: Haroon Ali
Id Number:4
Four subject Marks: 80 75 95 88
Student 2 information
Full Name: Ayesha Ali
Id Number :6
Four subject Marks: 75 95 65 77
Student 3 information
Full Name: Ehsan Ali
Id Number :8
Four subject Marks: 55 98 84 90
Lab Manual- 05
Topic: SOLID Design Principles-Open-Closed Principle (OCP) - Example
You have to write a program which can calculate area of triangle. Your developed program was
working fine but After few days a requirement arise and you want to calculate the area of
rectangle also and for this purpose you have to modify the program. The modification of the
program leads to the violation of the OCP principle. Now you have to write program in a way
that follow the OCP principle. OCP mean open for extension and close for modification.
Solution:
Pseudo code/Program without using OCP principle
If we want to calculate the area of Rectangle then the rectangle class will be like this:
If we want to add any other shape then again we have to modify AreaCalculator class which will
make it more messy and difficult to maintain if we add more shapes.
But If we use Open/Close principle then this problem can be solved. Following is the code that
implements open close principle. In this program if area of new shape required we simply add
class of that shape without modifying the existing class. Thus this is open for extension and
closed for modification.
#include <iostream>
class Shape
protected:
public:
{
width = a;
height = b;
};
public:
double area ()
};
public:
double area ()
};
int main ()
Shape *sPtr;
Rectangle rectangle;
sPtr = &rectangle;
cout << "Rectangle' Area is " << sPtr -> area() << endl; //output rectangle area
Triangle triangle;
sPtr = ▵
cout << "Triangle's Area is " << sPtr -> area() << endl; //output triangle area
return 0;
}
Lab Manual- 06
Topic: Design Pattern
Case Study:
Consider a scenario of a bank where we calculate monthly interest on different types of bank accounts.
Initially, we only have two types of accounts:
Current Account
Savings Account
Current account with an interest rate of 2% per year and savings account with 4% per year. Our account
types are defined by an enum.
Now, our next requirement is to add support for two other accounts.
Freedom Account
Munafa Account
The Freedom Account paying 6% per year, and Munafa Account that pays 7.5% per year but only if
customer’s minimum balance does not fall below PKR 100,000. We will modify our method accordingly
The finance team is planning to utilize our interest calculator for some other account like to calculate
the interest on consumer loans. However, their interest rates are not fixed, they are linked to the state
bank interest rate which we have to get through a web service. Not only are we dealing with more and
more types of accounts, the calculation logic is also becoming more complex.
Now, the problem is, with every new requirement our code is going to deteriorate. And this will create
difficult for us to understand the code. A single method is trying to handle multiple scenarios and code is
getting complex, we need to address this issue.
Which pattern can help us to address this issue? Name the pattern and perform the necessary steps
using java.
Solution:
Strategy pattern defines a family of algorithms, encapsulates each one, and makes them
interchangeable. Strategy lets the algorithm vary independently from clients that use it.
1. Figure out the areas in your code which are going to change and separate them.
2. Always program to an interface
In our scenario, according to the guidelines, we have successfully identified that we are changing the
logic for calculating interest based on the account’s types we are working with.
Now, considering the second guideline, we will define an interface to handle the input and output of our
account balance and interest calculations.
Note that our interface only deals with account balances - it doesn't care about account type, as each
action will already be specific to a specific account type. Our next step is to develop a strategy to deal
with each of our calculations.
Each calculation is now isolated to its own class, making the individual calculations much easier to
understand - they are no longer surrounded with clutter. Next, we'll refactor our calculator.
That’s it. We've moved the calculation logic out of the calculator itself.
Lab Manual- 07
Topic: State Design Pattern – An Example
As we studied in lectures, the State Pattern allows an object to change its behavior when it’s
internal state changes. The object will appear to change its class.
Context: It shows an interface to the client for interaction. It maintains references to concrete
state object which may be used to define current state of object.
State: It defines interface for declaring what each concrete state should do.
ConcreteState: It provides execution for functions defined in State.
Scenario:
Let’s take an example of a mobile mode state; you are required to write a java code for a mobile
mode. As we know that there are different alert modes in a mobile phone i.e., Sound, Vibration
and Mute. Based on this alert mode, when an alert is to be done, behavior of the mobile changes.
class Alert_Mode_Context
{
private Mobile_Alert_Mode presentMode;
public Alert_Mode_Context()
{
presentMode = new Sound();
}
The Extract Method is one of the most commonly used technique for refactoring code. With this
method, when we examine a piece of code, we can find that there is too much going on in one
place in our code, and we further see that there are one or more "chunks" of the code that can be
re-shaped in separate methods.
1. ReadData()
2. TaxCalculation()
3. GPFundCalculation()
4. NetSalaryCalc()
import java.util.Scanner;
public class Main
{
public double BasicPay, NetSalary, IncomeTax=0,GPFund=0;
public int grade;
Scanner kbd=new Scanner(System.in);
public static void main(String[] args) {
GPFund=(double)10/100*BasicPay;
System.out.println("GP fund Subscription is " +GPFund);
}
// 4. Extracted method for calculating net salary of the employee
void NetSalaryCalc()
{
NetSalary=BasicPay-(IncomeTax+GPFund);
System.out.println("Net Salary of Employee = " +NetSalary);
}
}
Step 5: Output Returned from the Program:
This is the same output result obtained from the code provided at 1. “Sample Code Fragment”
portion and 2. “Step 4” of the solution part.
Lab Manual- 09
Topic: MVC (Model View Controller) Pattern Explained by implementing of
a simple Java Program.
Model View Controller (MVC) Pattern in Java splits the given application into three
interconnected parts which are (model, view and controller) in order to separate internal
representations of information from the ways that information is presented to and accepted from
the user.
In MVC Pattern the user is not allowed to directly make connection with the data sources, but
he/she has to interact with the top-level layers to access the data. The user can interact with the
view and with the controller, but not with the model.
Solution:
Procedure:
In order to implement MVC design pattern, we will create the following three classes.
StudentModel Class, which contains only the pure application data, it contains no logic
describing how to present the data to a user.
StudentView Class, which defines the presentation of data. It knows how to access the
model’s data.
Controller Class, which acts as an interface between the Model and the View parts and it
intercepts all the incoming requests.
We will explore these classes one by one and finally merge them into a single program and run it
to verify its outputted result.
class StudentView {
public void printStudentInformation(StudentModel std) {
System.out.println("------------------------------------------------------- ");
System.out.println("Student's Record:");
\nDepartment = "+std.getDepartment());
System.out.println("------------------------------------------------------- ");
}
Step 3: Implementation of the “Controller” Class:
Controller acts on both model and view. It controls the data flow into model object and updates
the view whenever data changes. It keeps view and model separated from each other. The code
for the controller class is given as:
class Controller {
private StudentModel studentModel;
private StudentView studentView;
System.out.println("------------------------------------------------------- ");
System.out.println("Student's Record:");
\nDepartment = "+std.getDepartment());
System.out.println("------------------------------------------------------- "); }
class Controller {
int stId=scan.nextInt();
System.out.println("Enter Student Name:");
studentModel.setId(stId);
studentModel.setName(sname);
studentModel.setDepartment(dept);
controller.setStudentDepartment("Mathematics");
}}
Problem Statement: Suppose a trading system in which trading decision making are driven by
data from 3 sources: a stock ticker, an index watcher, and a CNN News Feed. The data from the
stock ticker and index watcher is first analysed before being forwarded to the trading manager
via an alert manager. The CNN News Feed interacts with the Trading Manager directly. You are
required to draw interaction diagram by using UML.
Solution:
Lab Manual- 11
Topic: Quality Attributes
Task:
Quality attribute (QA) is a measurable or testable property of a system that is used to indicate the
extent to which the system meets the needs of its stakeholders. Considering the case study given below,
identify the measurable properties of the given system, and mention the quality attribute against each
identified property in the provided table.
CASE STUDY:
Software development process has a variety of artefacts like software specification document, design
document, source files, test cases, test reports, etc. Each phase of software development produces it
respective artefacts that are maintained separately. The management of these artefacts is a challenging task.
We, CollabHub Inc., have been experiencing artefacts inconsistency issues for last 5 years.
After many meetings and brainstorming activities with stakeholders, we have decided to design a solution
for our project managers to keep track of the software artefacts. We are already keeping track for out
software artefacts using a good trace matrix. But it requires a lot of effort for maintenance.
The new system would be more like a hybrid project management tool that functions as a team collaboration
platform as well as an artefact management system. The system will be specifically designed for software
engineers and project managers, so it should have a conservative feel and appearance.
The system should allow the assignment of different roles and access permissions, but only the project
manager should have the privilege of assigning roles to the project team. We need to make sure that artefacts
links are accessible to the project team, and they are only accessing the links they are authorized to.
The system will also routinely handle the one-time, periodic, and ongoing project’s artefacts with ease,
including file indexing, inventory set up with retention schedules, and more. File indexing will be prevented
by everyone except the project managers.
We need to make sure that it does not take more than 60 seconds for the system to update the file index.
This can take a long time, but only if such processes are automated. In addition, the system should complete
the request to display artefacts such as sequence diagrams, case diagrams or any other antiques within 5
seconds.
We need to make sure that the data does not leave the organization without encryption. As mentioned
earlier, this system will be used by project teams, engineers and managers, so there should be proper FAQ
and user guide in place. We have a strict deadline; we look forward to seeing this system by the end of this
year.
… …
SOLUTION
Software development process has a variety of artefacts like software specification document, design
document, source files, test cases, test reports, etc. Each phase of software development produces it
respective artefacts that are maintained separately. The management of these artefacts is a challenging task.
We, CollabHub Inc., have been experiencing artefacts inconsistency issues for last 5 years.
After many meetings and brainstorming activities with stakeholders, we have decided to design a solution
for our project managers to keep track of the software artefacts. We are already keeping track for our
software artefacts using a good trace matrix. But it requires a lot of effort for maintenance.
The new system would be more like a hybrid project management tool that functions as a team collaboration
platform as well as an artefact management system. The system will be specifically designed for software
engineers and project managers, so it should have a conservative feel and appearance. The system will be
initially available for normal use from 06:00 to 23:59 hours Monday to Saturday and for system
maintenance purposes from 00:00 to 02:00 hours once a week.
The system should allow the assignment of different roles and access permissions, but only the project
manager should have the privilege of assigning roles to the project team. We need to make sure that artefacts
links are accessible to the project team 99% of the time without failure, and they are only accessing the
links they are authorized to.
The system will also routinely handle the one-time, periodic, and ongoing project’s artefacts with ease,
including file indexing, inventory set up with retention schedules, and more. File indexing will be prevented
by everyone except the project managers.
We need to make sure that it does not take more than 60 seconds for the system to update the file indices.
This can take a long time, but only if such processes are automated. In addition, the system should complete
the request, to display artefacts such as sequence diagrams, use case diagrams or any other artefacts, within
5 seconds.
We need to make sure that the data does not leave the organization without encryption. As mentioned
earlier, this system will be used by project teams, engineers, and managers, so there should be proper FAQ’s
and user guide in place. We have a strict deadline; we look forward to seeing this system by the end of this
year.
We are already keeping track for out software artefacts using a good trace Maintainability
matrix. But it requires a lot of effort for maintenance.
The system will be specifically designed for software engineers and Usability
project managers, so it should have a conservative feel and appearance.
The system will be initially available for normal use from 06:00 to 23:59 Availability
hours Monday to Saturday and for system maintenance purposes from
00:00 to 02:00 hours once a week.
The system should allow the assignment of different roles and access Security
permissions, but only the project manager should have the privilege of
assigning roles to the project team.
We need to make sure that artefacts links are accessible to the project team Reliability
99% of the time without failure
And they (team members) are only accessing the links they are authorized Security
to.
File indexing will be prevented by everyone except the project managers. Security
We need to make sure that it does not take more than 60 seconds for the Performance
system to update the file indices.
In addition, the system should complete the request, to display artefacts Performance
such as sequence diagrams, use case diagrams or any other artefacts,
within 5 seconds.
We need to make sure that the data does not leave the organization without Security
encryption.
As mentioned earlier, this system will be used by project teams, engineers, Usability
and managers, so there should be proper FAQ’s and user guide in place.
Lab Manual- 12
Topic: Agility and Architecture Design
ABC Pvt. limited wants to develop an inventory system. They hired a Cyber Solution Pvt. Ltd.
software development company for this development. First Cyber Solution Pvt. Ltd. have to
develop system architecture based on initial requirements provided by the ABC Pvt. Ltd. company.
After some time, ABC Pvt. Ltd. realize that Cyber Solution’s staff do not giving proper attention
towards design and architecture of the system. They just finalizing the architecture and just rushing
for direct development and final output. The ABC Pvt. Ltd understands that requirements may
change during development and the architecture may have to be updated. They want cyber solution
Pvt. Ltd. to develop agile architecture which can later updated when any change in requirement
occurs.
Do you think that it is a good approach to develop agile architecture which can be later updated?
Solution:
a. Do you think that it is a good approach to develop agile architecture which can be
later updated?
• Yes, Wherever possible, design your application so that it can change over time to
address new requirements and challenges. Modern thinking on architecture assumes that
your design will evolve over time and that you cannot know everything you need to know
up front in order to fully architect your system. Your design will generally need to evolve
during the implementation stages of the application as you learn more, and as you test the
design against real-world requirements. Create your architecture with this evolution in
mind so that it will be agile in terms of adapting to requirements that are not fully known
at the start of the design process.
• Consider using an incremental and iterative approach to refining your architecture. Do not
try to get it all right the first time—design just as much as you can in order to start testing
the design against requirements and assumptions. Iteratively add details to the design
over multiple passes to make sure that you get the big decisions right first, and then focus
on the details. A common pitfall is to dive into the details too quickly and get the big
decisions wrong by making incorrect assumptions, or by failing to evaluate your
architecture effectively. This iterative and incremental approach allows you to get the big
risks out of the way first, iteratively render your architecture, and use architectural tests to
prove that each new baseline is an improvement over the last.
Lab Manual- 13
Topic: Architectural Patterns
Combine all
four parts
Add sauce
into it
Customer
Figure 1
Points to Consider:
The application :
Problem:
What should be the application’s deployment architecture?
Solution:
The application is deployed as a single monolithic application.
For example, a Java web application consists of a single WAR file that runs on a web container
such as Tomcat. A Rails application consists of a single directory hierarchy deployed using either,
for example, Phusion Passenger on Apache/Nginx or JRuby on Tomcat. You can run multiple
instances of the application behind a load balancer in order to scale and improve availability.
Conclusion:
This solution has various benefits:
Simple to develop
Simple to deploy
Simple to scale
Lab Manual- 15
Problem:
What should be the application’s deployment architecture?
Solution:
This application is deployed using Cloud Computing Architecture.
Microsoft Azure
Oracle Cloud
Google Cloud
IBM Cloud
Amazon Web Services
Alibaba Cloud
SAP
Cloud computing technology is used by both small as well as large organizations to store the
information in cloud and access it from anywhere at any time using an Internet connection.
Front End
Back End
The below diagram shows the architecture of cloud computing -
Conclusion:
This solution has a number of benefits including:
Cost effective
Flexible and Scalable
Data Security
Excellent accessibility
Mobility
Lab Manual- 16
Points to Consider:
The same application was designed (in our Lab manual-14) using the monolithic architecture.
Despite its too many benefits, there are some drawbacks of monolithic architecture, because of the
“all-in-one structure”.
Alternate Solution:
In order to address the issues faced during adopting monolithic architecture, we need to use /
identify an architecture that structures this application as a set of loosely coupled, collaborating
services which are:
Problem:
What should be the application’s deployment architecture?
Solution:
This application is deployed using Micro-service architecture.
For example, services communicate using either synchronous protocols such as HTTP/REST or
asynchronous protocols such as AMQP. Services can be developed and deployed independently
of one another. Each service has its own database in order to be decoupled from other services.
Conclusion:
This solution has a number of benefits:
Improved maintainability - each service is relatively small and so is easier to understand and
change
Better testability - services are smaller and faster to test
Better deployability - services can be deployed independently
It enables you to organize the development effort around multiple, autonomous teams. Each
team can develop, test, deploy and scale their services independently of all of the other teams.
Improved fault isolation. For example, if there is a memory leak in one service then only that
service will be affected. The other services will continue to handle requests.
Eliminates any long-term commitment to a technology stack.