2. Review OOP
• What is Class, Object & Method?
• What is Abstraction and Inheritance?
• What is Overloading and Overriding in Polymorphism?
7/26/2023 OOP IN SOFTWARE DESIGN 2
3. OOP Essentials
1st step in OOP development is to identify the object and
establish relationship among them
Type of relationship
Association
Aggregation
Inheritance
7/26/2023 OOP IN SOFTWARE DESIGN 3
4. Association
Represent general binary relationship that describes an
activity between two classes.
Illustrated using solid lines
May have role name for each class involved which
describes the role played by the class in the relationship.
Each class involved may specify multiplicity. It could be a
number or interval, describes the number of object being
involved in the relationship
7/26/2023 OOP IN SOFTWARE DESIGN 4
6. Association
Association may exist between objects of the same class.
Association is usually represented as a data field in the
class.
7/26/2023 OOP IN SOFTWARE DESIGN 6
7. Association
public class Student {
private Course[] courseList;
// data field, constructor
// method
}
public class Course {
// data field, constructor
// method
}
public class Faculty {
private Course[] courseList;
// data field, constructor
// method
}
7/26/2023 OOP IN SOFTWARE DESIGN 7
public class Employee {
private Employee supervisor;
// data field
// constructor
// method
}
8. Association Team Discussion
A small software house in Bandung has a rule that limiting
one project manager’s responsibility only to one project
while he/she can lead at least one or more small team
related to software modules for the project.
Determine the relationship between Project Manager, The
Project and the Team, please write the class relationship.
7/26/2023 OOP IN SOFTWARE DESIGN 8
9. Aggregation
Special form of association that represents an ownership
between two classes
Models relationship like : has-a, owns, part-of, employed-
by…
An object may be owned by several other aggregated
objects.
If an objects is exclusively owned by an aggregated
object, the relationship is referred to as composition.
7/26/2023 OOP IN SOFTWARE DESIGN 9
10. Aggregation
public class FinanceConsultant {
private Broker[] brokerList;
//data field
//constructor
//method
}
7/26/2023 OOP IN SOFTWARE DESIGN 10
public class Share {
private Broker broker;
//data field
//constructor
//method
}
11. Class Design Guidelines
Class should describe a single entity or a set of similar
operations.
Single entity with too many responsibilities can be broken
to several classes to separate responsibilities.
Classes are designed for reuse.
Provide a public default constructor and override the
equals and toString method whenever possible.
Follow standard Java programming style and naming
conventions.
7/26/2023 OOP IN SOFTWARE DESIGN 11
12. Inheritance vs Composition
Inheritance representing is-a relationship.
Composition representing has-a relationship.
Use Inheritance if polymorphism is desirable.
Use Composition if you don’t care about polymorphism
and wants more flexibility to your design.
7/26/2023 OOP IN SOFTWARE DESIGN 12
13. Inheritance vs Composition
public class Person {
public Person() { }
private String name;
// getter and setter method
}
public class Mahasiswa extends Person {
public Mahasiswa() { }
private String npm;
// getter and setter method
}
7/26/2023 OOP IN SOFTWARE DESIGN 13
public class ProjectManager {
public ProjectManager() { }
private String firstName;
private String lastName;
// getter and setter method
}
public class Project {
public Project() { }
private String projectName;
private ProjectManager projectManager;
// getter and setter method
}
14. Inheritance
Models the is-a relationship between two classes.
Strong is-a relationship
Describes a direct inheritance relationship between two classes.
Represented using extends.
Example : public class Mahasiswa extends Person { }
Weak is-a relationship
Describes that a class has certain properties. Can be
represented using interfaces
Example : public class Purchase implements Transaction { }
7/26/2023 OOP IN SOFTWARE DESIGN 14
15. Inheritance vs Abstract
Strong is-a relationship better use abstract class.
Weak is-a relationship better use interfaces.
Interfaces are more flexible than abstract class, subclass
can only extends one superclass but may implement
many interfaces.
Interfaces doesn’t have concrete methods.
Both can be combined. ex. Set or List in Java Collection
Framework.
7/26/2023 OOP IN SOFTWARE DESIGN 15
16. Discussion
A small CD rental wants to build a database system so they
can manage their CDs collection. The objects involved in the
system are Customer (anyone who borrow CDs), Employee
(anyone who runs the rental’s management), and the CD
itself. Create the classes and their relationship.
7/26/2023 OOP IN SOFTWARE DESIGN 16