Lecture 2 - 2024
Lecture 2 - 2024
Course Code: CS
l.abozaid@fci -cu.edu.eg
Existing System
Why Need Software Design?
Development and maintenance costs
◦ Maintainability can be improved by reducing the complexity of system components.
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
Each object has its own identity even if two objects have exactly the same
attributes. They are still different separate objects.
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
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?
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.
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 }
}`
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?
This way, we declare that the class ColorCircle inherits the methods and variables of
Circle class . . . . . only it also has color information.
Or
A superclass (also parent or base ) has general features that subclasses (child or derived ) refine
and elaborate.
29
A Problem
Suppose you want to define objects to represent circles, squares, rectangles, and curves.
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() { ... }
}
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.
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
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.
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
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?
• 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.
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.
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?
86
• Is this an improvement? Why?
LECTURE 1: ADVANCED TOPICS IN SOFTWARE ENGINEERING
Questions ?