CS680AH2 Homework: Software Quality Assurance - OOP Analysis
VerifiedAdded on 2023/06/15
|11
|2110
|471
Homework Assignment
AI Summary
This document presents a solution to a Software Quality Assurance homework assignment (CS680AH2) focusing on object-oriented programming (OOP) principles and metrics. It explains key concepts such as inheritance, polymorphism, and data encapsulation, providing code examples to illustrate each principle. The solution also delves into coupling and cohesion types in OOP, discussing various forms like content coupling, common coupling, and high cohesion. Furthermore, it identifies and describes at least twelve object-oriented metrics, analyzing their relationship to polymorphism, encapsulation, and inheritance. Finally, the assignment highlights critical object-oriented metrics for re-using a program module/class, such as Lack of Cohesion in method, Operation complexity, Coupling between classes and weighted method per class.

_____________________________________________________________________________________________
CS680AH2 Software Quality Assurance
Homework #3 Project
Student’s Name: ____________________________________
Please, submit your CS680AH2 Homework-3 Report (in MS Word 97-2003 document or PDF
file format)
1. (15 pts.) Explain the principle of the inheritance. Give an example of class inheritance
(from a computer program selected for your project).
Inheritance is a principle of class hierarchy. It can be defined as an ability of an individual
object to take behavior and functionality of other objects. It is a way through which one class can
inherit methods and attributes of another class. In this when a class in derived or inherited from
another class then it is known as “IS-A” type of relationship. This can be explained with an
example given below from a project in which calculation of area of different shapes will be done:
public class Shape {
protected int height;
protected int width;
public Shape(int h, int w) {
height = h;
width = w;
}
public int area() {
return height * width;
}
public int getH () { return height; }
public int getW () { return width; }
1
CS680AH2 Software Quality Assurance
Homework #3 Project
Student’s Name: ____________________________________
Please, submit your CS680AH2 Homework-3 Report (in MS Word 97-2003 document or PDF
file format)
1. (15 pts.) Explain the principle of the inheritance. Give an example of class inheritance
(from a computer program selected for your project).
Inheritance is a principle of class hierarchy. It can be defined as an ability of an individual
object to take behavior and functionality of other objects. It is a way through which one class can
inherit methods and attributes of another class. In this when a class in derived or inherited from
another class then it is known as “IS-A” type of relationship. This can be explained with an
example given below from a project in which calculation of area of different shapes will be done:
public class Shape {
protected int height;
protected int width;
public Shape(int h, int w) {
height = h;
width = w;
}
public int area() {
return height * width;
}
public int getH () { return height; }
public int getW () { return width; }
1
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

_____________________________________________________________________________________________
public void setH (int h) { return height; }
public void setW (int w) { return width; }
}
public class Triangle extends Shape {
public Triangle(int h, int w) {
super(h, w);
}
public int area() {
return super.area() / 2;
}
}
2. (15 pts.) Explain the principle of the polymorphism. Give an example of polymorphism
(from a computer program selected for your project).
Polymorphism can be defined as a concept of treating classes in hierarchy in a uniform manner.
It can also be defined as a kind of method in class that perform different things as per object’s
class whenever it is called. The only difference between inheritance and polymorphism is that in
inheritance, class inherit properties of another class. Whereas in polymorphism method is called
by another object and can be called in different forms.
For example: we have a class named shapes and it has a method using which areas method can
be used by different classes of different shapes. This example can be provided from a project that
focuses upon calculation of area, shape and size of different kinds of shapes:
class Shape {
public void area() {
System.out.println("Area of ");
}
}
2
public void setH (int h) { return height; }
public void setW (int w) { return width; }
}
public class Triangle extends Shape {
public Triangle(int h, int w) {
super(h, w);
}
public int area() {
return super.area() / 2;
}
}
2. (15 pts.) Explain the principle of the polymorphism. Give an example of polymorphism
(from a computer program selected for your project).
Polymorphism can be defined as a concept of treating classes in hierarchy in a uniform manner.
It can also be defined as a kind of method in class that perform different things as per object’s
class whenever it is called. The only difference between inheritance and polymorphism is that in
inheritance, class inherit properties of another class. Whereas in polymorphism method is called
by another object and can be called in different forms.
For example: we have a class named shapes and it has a method using which areas method can
be used by different classes of different shapes. This example can be provided from a project that
focuses upon calculation of area, shape and size of different kinds of shapes:
class Shape {
public void area() {
System.out.println("Area of ");
}
}
2

_____________________________________________________________________________________________
class Triangles extends Shape {
public void area() {
System.out.println("Triangle is ½ * base * height ");
}
}
class Circle extends Shape {
public void area() {
System.out.println("Circle is 3.14 * radius * radius ");
}
}
class Main {
public static void main(String[] args) {
Shapes myShape = new Shapes();
Shapes myTriangle = new Triangle();
Shapes myCircle = new Circle();
myShape.area();
myTriangle.area();
myShape.area();
myCircle.area();
}
}
3. (15 pts.) Explain the principle of data encapsulation. Give an example of data
encapsulation (from a computer program selected for your project).
Encapsulation can be defined as a kind of method that can be used to hide data inside the
object so that it can only be used with the help of a public interface. In other language, it can be
said that it is a method of restricting direct access to some objects or certain variables of an
object. With the help of this methods developers can easily hide data members or functions
3
class Triangles extends Shape {
public void area() {
System.out.println("Triangle is ½ * base * height ");
}
}
class Circle extends Shape {
public void area() {
System.out.println("Circle is 3.14 * radius * radius ");
}
}
class Main {
public static void main(String[] args) {
Shapes myShape = new Shapes();
Shapes myTriangle = new Triangle();
Shapes myCircle = new Circle();
myShape.area();
myTriangle.area();
myShape.area();
myCircle.area();
}
}
3. (15 pts.) Explain the principle of data encapsulation. Give an example of data
encapsulation (from a computer program selected for your project).
Encapsulation can be defined as a kind of method that can be used to hide data inside the
object so that it can only be used with the help of a public interface. In other language, it can be
said that it is a method of restricting direct access to some objects or certain variables of an
object. With the help of this methods developers can easily hide data members or functions
3
You're viewing a preview
Unlock full access by subscribing today!

_____________________________________________________________________________________________
within an object or a class. An example can be provided from a project in which calculation of
area of different shapes will be done. For example:
Public class shapes
{
Privare String ShapeName; //private method that has been encapsulated
Public string getName()
{
Return ShapeName;
}
public void setName(String ShapeName){
this. ShapeName = ShapeName
}
This class has encapsulated method and variable that cannot be used oy anther class
which is not public.
4. (15 pts.) Briefly describe the coupling types in object-oriented programming. Give a few
examples of different coupling types (from a computer program selected for your
project).
Coupling can be defined as interaction between two classes or functions that violets
principle of hiding information. Some of the main types of coupling types of Object- oriented
programming are as follows:
Content coupling: it is a kind of coupling in which one class modified content of another
class
Common Coupling: it is a kind of coupling in which two classes can access same shared
data. For example, a global variable.
Control coupling: it is a kind of coupling in which one function can control flow of another
function.
4
within an object or a class. An example can be provided from a project in which calculation of
area of different shapes will be done. For example:
Public class shapes
{
Privare String ShapeName; //private method that has been encapsulated
Public string getName()
{
Return ShapeName;
}
public void setName(String ShapeName){
this. ShapeName = ShapeName
}
This class has encapsulated method and variable that cannot be used oy anther class
which is not public.
4. (15 pts.) Briefly describe the coupling types in object-oriented programming. Give a few
examples of different coupling types (from a computer program selected for your
project).
Coupling can be defined as interaction between two classes or functions that violets
principle of hiding information. Some of the main types of coupling types of Object- oriented
programming are as follows:
Content coupling: it is a kind of coupling in which one class modified content of another
class
Common Coupling: it is a kind of coupling in which two classes can access same shared
data. For example, a global variable.
Control coupling: it is a kind of coupling in which one function can control flow of another
function.
4
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

_____________________________________________________________________________________________
For example:
Void shape(int x){
if (x == 0)
return false;
else
return true;
}
void shape(){
shape(1);
}
Routine call coupling: when one function directly calls another function without passing any
kind of argument then it is known as a routine call coupling.
Data coupling: when one function passes data to another function for calculation is known as
data coupling
Type-use coupling: when one of the data member of class B is of class A type then it is
known as type use coupling.
Stamp coupling: When one of the class B function signature has class A’s argument or its
return type. An example can be provided from a project in which calculation of area of
different shapes will be done. For example:
class Shape{
int area;
};
5
For example:
Void shape(int x){
if (x == 0)
return false;
else
return true;
}
void shape(){
shape(1);
}
Routine call coupling: when one function directly calls another function without passing any
kind of argument then it is known as a routine call coupling.
Data coupling: when one function passes data to another function for calculation is known as
data coupling
Type-use coupling: when one of the data member of class B is of class A type then it is
known as type use coupling.
Stamp coupling: When one of the class B function signature has class A’s argument or its
return type. An example can be provided from a project in which calculation of area of
different shapes will be done. For example:
class Shape{
int area;
};
5

_____________________________________________________________________________________________
class Triangle{
area var;
void calculate(area data){
}
};
Import coupling: when an inbuild library is used inside a program is known as import
coupling.
For example
Import Java.util
External: when communication with external system is done then it is known as external
coupling.
5. (15 pts.) Briefly describe the cohesion types in object-oriented programming. Give a few
examples of different cohesion types (from a computer program selected for your
project).
Cohesion can be defined as a degree to which elements inside a program belong together. It
can also be defined as a strength of relationship between data and methods of class. There are
two main kinds of Cohesion types in object- oriented programming, some of them have been
explained below in detailed manner:
Low cohesion: when a class is crated for doing different kinds of task instead of focusing upon a
single task then it is known as low cohesion. It is one of the worst types of programming and
require frequent lots of modifications instead of small changes.
For example:
Class Shapes
{
//code for triangle area;
6
class Triangle{
area var;
void calculate(area data){
}
};
Import coupling: when an inbuild library is used inside a program is known as import
coupling.
For example
Import Java.util
External: when communication with external system is done then it is known as external
coupling.
5. (15 pts.) Briefly describe the cohesion types in object-oriented programming. Give a few
examples of different cohesion types (from a computer program selected for your
project).
Cohesion can be defined as a degree to which elements inside a program belong together. It
can also be defined as a strength of relationship between data and methods of class. There are
two main kinds of Cohesion types in object- oriented programming, some of them have been
explained below in detailed manner:
Low cohesion: when a class is crated for doing different kinds of task instead of focusing upon a
single task then it is known as low cohesion. It is one of the worst types of programming and
require frequent lots of modifications instead of small changes.
For example:
Class Shapes
{
//code for triangle area;
6
You're viewing a preview
Unlock full access by subscribing today!

_____________________________________________________________________________________________
//code for triangle volume;
//code for circle area;
}
High Cohesion: When a class is created and designed for performing a specific type of function
or a task then it is called high cohesion. It is one of the most suitable and appropriate approach
for programming. An example can be provided from a project in which calculation of area of
different shapes will be done
For example:
class Shape {
public void area() {
System.out.println("Area of ");
}
}
class Triangles extends Shape {
public void area() {
System.out.println("Triangle is ½ * base * height ");
}
}
class Circle extends Shape {
public void area() {
System.out.println("Circle is 3.14 * radius * radius ");
}
}
6. (15 pts.) Name at least 12 object-oriented metrics and their relationship to polymorphism,
encapsulation, and inheritance:
Metric Polymorphism Encapsulation Inheritance
Weighted method per
class
Understand
complexity of
Specify
complexity of
Specifying complexity
of inherence of
7
//code for triangle volume;
//code for circle area;
}
High Cohesion: When a class is created and designed for performing a specific type of function
or a task then it is called high cohesion. It is one of the most suitable and appropriate approach
for programming. An example can be provided from a project in which calculation of area of
different shapes will be done
For example:
class Shape {
public void area() {
System.out.println("Area of ");
}
}
class Triangles extends Shape {
public void area() {
System.out.println("Triangle is ½ * base * height ");
}
}
class Circle extends Shape {
public void area() {
System.out.println("Circle is 3.14 * radius * radius ");
}
}
6. (15 pts.) Name at least 12 object-oriented metrics and their relationship to polymorphism,
encapsulation, and inheritance:
Metric Polymorphism Encapsulation Inheritance
Weighted method per
class
Understand
complexity of
Specify
complexity of
Specifying complexity
of inherence of
7
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

_____________________________________________________________________________________________
methods within a
class
methods and
variables to be
used
methods within class
Depth of inheritance tree Helps in designing
class and method
complexity
Helps in gaining
understanding of
class in much
better manner in
order to
understand level
of encapsulation
Length of inertance
and helps in finding
longest path to
inherited classes.
Number of children High number
increases
reusability
High level
indicates
inappropriate
level of
abstraction and
encapsulation
Can be used to count
immediate subordinate
class within
inheritance.
Coupling between classes Potential
modification that
can be made within
class and its
methods
Understanding
and increasing
reliability and
reusability of
variables,
methods till a
certain level.
Amount of
collaboration between
two classes
Response for a class Number of
methods that can
be potentially
executed again and
gain
Understanding
complexity of
class for
understanding in
order to reduce
complexity of
class
Type of classes that
can be potentially be
inherited
Lack of Cohesion in Helps in Helps in High Lack of
8
methods within a
class
methods and
variables to be
used
methods within class
Depth of inheritance tree Helps in designing
class and method
complexity
Helps in gaining
understanding of
class in much
better manner in
order to
understand level
of encapsulation
Length of inertance
and helps in finding
longest path to
inherited classes.
Number of children High number
increases
reusability
High level
indicates
inappropriate
level of
abstraction and
encapsulation
Can be used to count
immediate subordinate
class within
inheritance.
Coupling between classes Potential
modification that
can be made within
class and its
methods
Understanding
and increasing
reliability and
reusability of
variables,
methods till a
certain level.
Amount of
collaboration between
two classes
Response for a class Number of
methods that can
be potentially
executed again and
gain
Understanding
complexity of
class for
understanding in
order to reduce
complexity of
class
Type of classes that
can be potentially be
inherited
Lack of Cohesion in Helps in Helps in High Lack of
8

_____________________________________________________________________________________________
method understanding
access to different
methods to be
reused
understanding
access to
variables
Cohesion in method
helps in understanding
in how many parts
class is required to be
broken
Class size High class size
means lower
reusability of
methods
High class size
means
encapsulation of
too much
behaviour
High class size results
in decreased change of
appropriate inheritance
Number of operations
overridden by a subclass
Help in
understanding
methods in classes
that have been
redefined and
reused.
Design problem
that can occur
due to data or
method
wrapping
Understanding
methods within a sub
class inherited
Number of operations
added by a subclass
Helps in gaining
understating of
number of methods
within a class
Helps in
understanding
abstraction
violation
Helps in
understanding number
of methods that
appears in sub class
OO Testing Metrics Helps in
understanding
percentage of
methods that
should be public,
private or
protected.
Helps in
understanding
whether variable
or method can be
hidden and
reused or not
Helps in
understanding
complexity of a class
to be inherited
Average operation size Helps in
understanding
whether a method
can be reused in
Helps in
understanding
ways in which
data or methods
Helps in
understanding number
of times a class can be
inherited
9
method understanding
access to different
methods to be
reused
understanding
access to
variables
Cohesion in method
helps in understanding
in how many parts
class is required to be
broken
Class size High class size
means lower
reusability of
methods
High class size
means
encapsulation of
too much
behaviour
High class size results
in decreased change of
appropriate inheritance
Number of operations
overridden by a subclass
Help in
understanding
methods in classes
that have been
redefined and
reused.
Design problem
that can occur
due to data or
method
wrapping
Understanding
methods within a sub
class inherited
Number of operations
added by a subclass
Helps in gaining
understating of
number of methods
within a class
Helps in
understanding
abstraction
violation
Helps in
understanding number
of methods that
appears in sub class
OO Testing Metrics Helps in
understanding
percentage of
methods that
should be public,
private or
protected.
Helps in
understanding
whether variable
or method can be
hidden and
reused or not
Helps in
understanding
complexity of a class
to be inherited
Average operation size Helps in
understanding
whether a method
can be reused in
Helps in
understanding
ways in which
data or methods
Helps in
understanding number
of times a class can be
inherited
9
You're viewing a preview
Unlock full access by subscribing today!

_____________________________________________________________________________________________
different way or
not.
of high
complexity can
be hidden
Operation complexity Complexity of
method helps in
understanding
whether it can be
used by or
processed in more
than one time.
By identifying
complexity of
class or method
it can be
identified
whether any
data, variable or
method is
required to be
hidden or
wrapped or not.
Helps in identifying
complexity of method
for understanding
which class can be
inherited
7. (10 pts.) What object-oriented metrics are critical for re-using a program module/class?
______ Lack of Cohesion in method ________ this score directly helps in understanding in
how many number of time a class can be broken down into sub classes and can be inherited.
Its high value helps in identifying number of multiple classes.
______ Operation complexity ________ it directly helps in understanding complexity of a
method using which it can be understood whether that method can be reused or class
consisting that method can be inherited or not this score should be kept as much lower as
possible.
_____ Coupling between classes _________it helps in understanding potential difficulties
that one can face while modifying a class. Not only this it can further help in understanding
collaboration between classes and sub classes.
10
different way or
not.
of high
complexity can
be hidden
Operation complexity Complexity of
method helps in
understanding
whether it can be
used by or
processed in more
than one time.
By identifying
complexity of
class or method
it can be
identified
whether any
data, variable or
method is
required to be
hidden or
wrapped or not.
Helps in identifying
complexity of method
for understanding
which class can be
inherited
7. (10 pts.) What object-oriented metrics are critical for re-using a program module/class?
______ Lack of Cohesion in method ________ this score directly helps in understanding in
how many number of time a class can be broken down into sub classes and can be inherited.
Its high value helps in identifying number of multiple classes.
______ Operation complexity ________ it directly helps in understanding complexity of a
method using which it can be understood whether that method can be reused or class
consisting that method can be inherited or not this score should be kept as much lower as
possible.
_____ Coupling between classes _________it helps in understanding potential difficulties
that one can face while modifying a class. Not only this it can further help in understanding
collaboration between classes and sub classes.
10
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

_____________________________________________________________________________________________
______ weighted method per class ________ this metric directly helps in understanding
reusability and complexity of method for understanding whether it should be reused or not.
This matrix level should be kept low.
Thank you. Good Luck!
11
______ weighted method per class ________ this metric directly helps in understanding
reusability and complexity of method for understanding whether it should be reused or not.
This matrix level should be kept low.
Thank you. Good Luck!
11
1 out of 11
Related Documents

Your All-in-One AI-Powered Toolkit for Academic Success.
+13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
© 2024 | Zucol Services PVT LTD | All rights reserved.