0% found this document useful (0 votes)
11 views

Lecture 2 - 2024

Uploaded by

Andrew Adel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Lecture 2 - 2024

Uploaded by

Andrew Adel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 88

Faculty of Computers and Artificial Intelligence

Master of Computer Science

Advanced Software Engineering


(Software Engineering 2)
Dr. Lamia Abo Zaid ‫ لمياء أبوزيد‬. ‫د‬

Course Code: CS
l.abozaid@fci -cu.edu.eg

LECTURE 1: ADVANCED TOPICS IN SOFTWARE ENGINEERING


Course Material
❑ Lecture Slides
❑ Selected papers from the literature
❑ Text books:
❑Other sources
❑Software Engineering Body of Knowledge
SWBOK
❑Miscellaneous papers /online sources

LECTURE 1: ADVANCED TOPICS IN SOFTWARE ENGINEERING


Course Material
❑ Course available on Google classroom
❑Course name: Advanced Software Engineering
2024-2025
❑ Course code: r7vjh6n

LECTURE 1: ADVANCED TOPICS IN SOFTWARE ENGINEERING


What is system Design? Problem
Bridge the gap
◦ between a problem and an existing system in a
manageable way
System
• How? Design
• Use Divide & Conquer:
1) Identify design goals
2) Model the new system design as a set
of subsystems
3) Address the major design goals.

Existing System
Why Need Software Design?
Development and maintenance costs
◦ Maintainability can be improved by reducing the complexity of system components.

Complexity depends on:


–Complexity of control structures;
–Complexity of data structures;
–Object, method (procedure) and
module size.
Why is Design so Difficult?
Analysis: Focuses on the application domain
Design: Focuses on the solution domain
◦ The solution domain is changing very rapidly

➢Design knowledge is a moving target

Design window: Time in which design decisions have to be


made.
Karl Wiegers , Thorny Issues in Software
Requirements
Requirements
Specification
Design Strategies & Methods
(Architectural) Design
Decisions
The design process consists mainly 4 activities
1. Suggest a solution Logical Design Details
2. Build a model of the solution
3. Evaluate the model against original requirements Detailed Design
4. Elaborate the model to produce to produce a Decisions

detailed specification of the solution


Physical Design Details
How do we get the Design Goals?
Let’s look at a small example

Current Situation:
◦ Computers must be used in the office
Why? Problem

What we want:
◦ A computer that can be used in mobile situations.
Let's revise important concepts

LECTURE 1: ADVANCED TOPICS IN SOFTWARE ENGINEERING


Objects have Identity
Identity means that data is quantized in into discrete, distinguishable, entities
called objects
An object can be concrete like a car, a file, …
An object can be conceptual like a feeling, a plan,…

Each object has its own identity even if two objects have exactly the same
attributes. They are still different separate objects.

Aly’s Car Sally’s Car


11
Objects Identity
Object identity is the property by which each object can be uniquely
identified and treated as a distinct software entity

Typically it is its memory address (or


handle) that is referred to by one or
more object identifiers (OID)

12
Classification
Classification means that objects with the same data structure (attributes) and
behavior (operations) belong to the same class
A class is an abstraction that describes the properties important for a specific
application

The choice of classes is arbitrary and application-dependent

We use DESIGN to choose proper classes

13
Classification
•Each object is an instance of a class
•Each object has a reference to its class (knows which
class it belongs to)

14
Abstraction
What is abstraction?
Given the house below, what could be a possible abstraction for it?

What does OOP have to do with abstraction?

15
Abstraction
A class abstracts a real concept according to the needs of a specific application.

Abstraction aims to isolate the aspects that are important for some purpose and suppress the
unimportant aspects.
◦ The purpose of abstraction determines what is important and what is not.

All abstractions are incomplete and inaccurate.

We use abstraction in modeling


◦ In modeling, do not search for the truth but for adequacy for some purpose.
◦ There is no single correct model for a problem. Only adequate and inadequate ones.
◦ A good model captures the crucial aspects of a problem and omits the rest.

16
Encapsulation
Encapsulation separates the external aspects of an object, that are
accessible to other objects, from the internal implementation details that
are hidden from other objects.
You can change the implementation of a class (to enhance performance,
fix bugs, etc.) without affecting the applications that use objects of this
class.

17
Encapsulation
It allows you to replace an algorithm with a faster one while keeping the class interface (public
methods) the same.
void sort () { // Bubble Sort
int i, j;
for (i = length - 1; i > 0; i-) {
List
for (j = 0; j < i; j++) {
- items: int [ ] if (items [j] > items [j + 1]) {
- length: int int temp = items [j];
items [j] = items [j + 1];
+ List (array): void items [j + 1] = temp;
+ search (int): bool }
+ getMax (): int }
+ sort(): void }
}`

void sort () { // Quick Sort


……….
}`
18
Encapsulation
It allows you to replace a data item with another one while keeping the class interface (public methods) the same.
List List
- items: int [ ] - items: vector<int>
- length: int

+ List (array): void + List (array): void


+ search (int): bool + search (int): bool
+ getMax (): int + getMax (): int
+ sort(): void + sort(): void

void sort () { // Bubble Sort


int i, j;
for (i = items.size()- 1; i > 0; i-) {
for (j = 0; j < i; j++) {
if (items [j] > items [j + 1]) {
swap (items [j], items [j + 1]);
}
}
}
} 19
Encapsulation
Data hiding. Information from within the object cannot be seen outside
the object.
Implementation hiding. implementation details within the object cannot
be seen from the outside.

20
Extending Circles
What should I do if I want to have a new kind of circle, ColorCircle, that behaves just like a
circle, but also has color information?

Copy the original Circle into a new ColorCircle class.


Example: ColorCircle
class ColorCircle
{
protected float radius;
protected Color color;
public ColorCircle (float r, Color c) {
radius = r; color = c;
}
public float Area () {
return Math.PI * radius * radius;
}
...
}
Example: ColorCircle
But now suppose I want to change the type of Area() to double.
Then I will need to change the code on two different places.

And suppose I want to add a method Circumference().


Then I will have to add this code on two different places.

This smells of bad design. . .


An Alternative Solution - Inheritance
class ColorCircle : Circle
{
protected Color color;
...
}

This way, we declare that the class ColorCircle inherits the methods and variables of
Circle class . . . . . only it also has color information.

A change to the original Circle class methods automatically propagates to the


ColorCircle class.
We say that

ColorCircle is a subclass of Circle;

Or

Circle is the superclass of ColorCircle.


Inheritance
Inheritance is the sharing of features (attributes and operations) among classes based on a
hierarchical relationship.

A superclass (also parent or base ) has general features that subclasses (child or derived ) refine
and elaborate.

Each subclass inherits all the features of its superclass.

Inheritance is one of the strongest features of OO technology.


Another mechanism for Reuse in OO
Aggregation
Aggregation is the ability to create new classes out of existing classes
Treating them as building blocks or components
Aggregation allows reuse of existing code
How could we apply aggregation to the Circle and ColorCircle example?
◦ Aggregation versus inheritance?
Abstraction in Action
Different abstractions for the concept of a car according to the application.
Car At Car Dealer Car
-motorCapacity: int -model: string
-model: string Car -licenseNumber: string
-make: string -problem: string
-year: int -model: string
-owner: string
-licenseNumber: string -make: string
-balance: float
-year: int
-isFinished: bool
+Car (int, ….): void -salePrice: int
+getMake (): string -paymentMethod: int
+Car (string,...): void
+printDetails(): void +printBlanace (): string
+........ +Car (string,...): void
+printDetails(): void
+sell (Customer): void
+........
+........
At Traffic Dept +........
At Repair Shop
28
Polymorphism
We have defined a method float Area() within the class Circle
We can call this method on all kinds of circles:
Circle mycircle1 = new Circle(4);
Circle mycircle2 = new ColorCircle(6,
Color.Red);
...
float area1 = mycircle1.Area();
float area2 = mycircle2.Area();
We call this phenomenon polymorphism.

29
A Problem
Suppose you want to define objects to represent circles, squares, rectangles, and curves.

A Square class could be a subclass of a Rectangle class.

But what is a good choice of superclass for both the Rectangle and Circle classes?

30
Abstract Class
An abstract class is a class without instances.

For example:
abstract class Shape {
public abstract void draw() { ... }
}

This declares a ‘dummy’ superclass, with a single method draw

Individual subclasses, such as Circle, Square, Rectangle or Curve, should


override the draw method with their own implementation.

31
Abstract Class
Abstract classes are placeholders for actual implementation classes.
The abstract class defines behavior and the subclasses implement that behavior.
Remember… You cannot create instances from abstract classes!
Whenever you find common behavior in two or more places, look to abstract that behavior, and
then reuse that behavior in a common class.

32
Polymorphism: Technical term
Polymorphism means that the same operation may behave differently for different classes.

An operation is a procedure or a transformation that the object performs or is subject to.

An implementation of an operation by a specific class is called a method.

33
Shape
- color: int Italic means
Polymorphism operation is
specified but not
+ Shape (int): void
+ getColor (): int implemented in
the base class
+ setColor (int): void
+ getArea(): float

Rectangle Circle Square


- length: float - radius: float - side: float
- width: float
+ Circle(int, int): void + Square(int, int): void
+ Rectangle ……. + getRadius(): float + getSide(): float
+ getArea(): float + setRadius(): float + setSide(): float
+ getArea(): float + getArea(): float

length x width  x radius2 side2


34
Interfaces
An interface is a signature describing a series of methods or
properties;
A class implements an interface if it defines these methods.
interface IDimensions
{
float getLength();
float getWidth();
}

35
Interfaces: Technical term
The term interface can mean different things:
Interface in the IDimension sense
But we also talk about the interface of a system or class as what
gets exposed to the outside world.

When we talk about interfaces, we’ll usually refer to the second


notion.

36
Interfaces versus abstract classes?
Interfaces:
A class may implement many interfaces.
An interface only defines public methods properties.
Used to organize objects that share some common property.

Abstract classes:
A class has one single superclass.
An abstract class may also specify private methods and properties.
Used to group closely related objects.
37
Example: Rock and Roll is Forever
Rock and Roll is Forever
Rick is the owner of guitar shop.
Rick decided to use a computer-based system for storing his inventory.
Rick needs a programming firm to build him a new search tool to help him match up a customer
to their dream instrument.
What classes do you think are needed for such a tool?
Rock and Roll is Forever
Guitar properties

Getters for the


properties
Rock and Roll is Forever
Let us look at the code
for Guitar.java
Rock and Roll is Forever
Let us look at the code for
Inventory.java.
Rock and Roll is Forever
How is the searching done within Inventory.java.
Rock and Roll is Forever
But … Rick started losing customers!
How?
◦ Erin is looking for a Fender Strat guitar made of Alter.

◦ But the tool shows no matches to Erin.


Rock and Roll is Forever

So what happened?
Why isn’t the tool returning the result?
Rock and Roll is Forever
We are at step 1.
Did we fulfill it?
Does the tool satisfy the customer
Actually no! We have two main problems:
needs?

• Using strings instead of


constants/objects.
• Hence, we cannot find
the match!
Does the tool satisfy the customer needs?
Actually no! We have two main problems:

• We need a list of
matches, not only one.
Does the tool satisfy the customer needs?
To address problem 1, we will get rid of string comparisons through enumerations.
Let us update the class diagram after using enumerations.
Does the tool satisfy the customer needs?
Does the tool satisfy the customer needs?
To address problem 2, we will change search() to return a list of matches.
Does the tool satisfy
the customer needs?
Now…
Back to our steps
Step 1 is done.
Let us check step 2.
Looking for problems
Looking for problems
Looking for problems
To help you figure out the problem, here are some tips:
1. Objects should do what their names indicate
2. Each object should represent a single concept.
3. Unused properties indicate an object that is doing more than one job.

Do we have such objects within our class diagram?


What OO principle can help us fix this problem?
Looking for problems
Looking for problems
Do we really need to supply a guitar object in the search() method, or only a
subset is enough?
How about we create another object that holds the guitar specs to search for?
◦ E.g., List search (GuitarSpec)
◦ We would have a Guitar class including the 6 guitar properties (serialID, price, builder, type,
…etc.)
◦ We would add a new GuitarSpec class including the 4 properties used for searching(builder,
type, …etc.)
◦ Any issues here?
Looking for problems
Looking for problems
Solving problems - Encapsulate to GuitarSpecs
Solving problems - Update your design

COPYRIGHT © 2011 SOHA MAKADY. ALL RIGHTS RESERVED 62


Let’s check if Inventory.java is well-designed
Consider the updated search() method below.
Do you see any expected problems if Rick considers adding a new feature?
Now…Let’s play some “Requirements Change!”

How easy is it to make


such a change to Rick’s
application?
Now…Let’s play some “Requirements Change!”
Think about what you need to do to add support for 12-string guitars.
Now…Let’s play some “Requirements Change!”
Now…Let’s play some “Requirements Change!”
Now…Let’s play some “Requirements Change!”

• Do you remember the terms


loosely coupled and tightly
coupled?
• Is this design loosely or tightly
coupled?
Now…Let’s try to solve the problem
Now…Let’s try to solve the problem

COPYRIGHT © 2011 SOHA MAKADY. ALL RIGHTS RESERVED 72


Now…Let’s try to solve the problem

COPYRIGHT © 2011 SOHA MAKADY. ALL RIGHTS RESERVED 73


Now…Let’s try to solve the problem Remember
“Delegation”!

COPYRIGHT © 2011 SOHA MAKADY. ALL RIGHTS RESERVED 74


Required Readings
Chapters 1 and 5 from the text book: McLaughlin, Brett, Gary Pollice, and David West. Head First
Object-Oriented Analysis and Design: A Brain Friendly Guide to OOA&D. " O'Reilly Media, Inc.",
2007.
Interfaces vs Abstract Classes
The SimUDuck App!
Joe works for a company that makes a highly
successful duck pond simulation game, SimUDuck.
The game can show a large variety of duck species
swimming and making quacking sounds.

• What classes do you expect to see in such design?

76
Interfaces vs Abstract Classes
The SimUDuck App!
Joe works for a company that makes a highly
successful duck pond simulation game, SimUDuck.
The game can show a large variety of duck species
swimming and making quacking sounds.

• The initial designers of the system used standard


OO techniques and created one Duck superclass
from which all other duck types inherit.
• What classes do you expect to see in such design?
77
Interfaces vs. Abstract Classes

78
Interfaces vs Abstract Classes
But the company need something really
impressive to show at the upcoming
shareholders meeting in Maui next week.
For the upcoming version of the SimUDuck
app, they decide to make the ducks fly

79
Interfaces vs Abstract Classes

80
Interfaces vs Abstract Classes

81
Interfaces vs Abstract Classes

82
Interfaces vs Abstract Classes

83
The SimUDuck App –
Joe thinks about
inheritance...

84
The SimUDuck App – Joe thinks about inheritance...

85
The SimUDuck App – How about an interface?

• What do you think of that design?

86
• Is this an improvement? Why?
LECTURE 1: ADVANCED TOPICS IN SOFTWARE ENGINEERING
Questions ?

LECTURE 1: ADVANCED TOPICS IN SOFTWARE ENGINEERING

You might also like