Object Oriented
Design
Java Basics
●
Objects
●
Classes
Object Oriented Programming
●
Organize code into objects
●
Objects contain attributes and methods
Class
●
Class describes the structure of an object
●
A class can be used to create objects
Class
Object
●
Object is an instance of the class
●
You can create multiple instances (objects) of
a single class
Object
Constructor
●
Constructor is used to simplify the creation
of objects
Java Access keywords
●
Most commonly used ones are
– public – Allows methods and attributes to be
accessed by anyone inside / outside the class
– private – Allows the methods and attribute
access within the class
– [default] – Allows the methods and attribute
access within the package
Java Access keywords
Static keyword
●
Static variables and methods belong to the
class itself
●
They can be used without instantiating new
objects
Static keyword
Main Design Principles
●
Abstraction
●
Encapsulation
●
Decomposition
●
Generalization
Decomposition
●
Break a component into separate parts
●
Combine parts to make a component
●
Break down a problems into pieces which are
easy to understand and solve
Decomposition
●
Association
- some relation / interaction
●
Aggregation
- belongs
●
Composition
- contains (whole cannot exist without parts)
Association
Aggregation
Composition
Abstraction
●
Focus on essential features of an object, ignore
unnecessary details
●
Model objects based on their behavior, not on
implementation.
●
This simplifies design and handling
●
Show ‘what’ an object can do without showing
‘how’
Encapsulation
●
Hide internal details of an object, expose
only what’s needed through interfaces
●
Protect the internal state of an object from
unauthorized access
Encapsulation
●
Bundle
– Data, Functions
●
Expose
- Interface
●
Restrict
Bundle and Restrict
Expose
Generalization
●
Extract common beahaviors from two or
more classes and combine them into a
generalized superclass
Other OOP concepts
●
Inheritance
●
Polymorphism
●
Cohesion
●
Coupling
Inheritance
●
Establish a parent-child relation
●
Child classes inherit attributes and methods
●
Promote code reuse and hierarchy
●
Similar to Generalization
Polymorphism
●
Ability of objects to respond differenty and
uniquely to a method call.
●
Allow one interface to be used for different
pourposes
●
Makes code more flexible
●
(This is different from Generalization)
Polymorphism
Cohesion
●
Represent the clarity of responsibilities of a
module
●
A good design must have high cohesion
Cohesion
Coupling
●
Measures the complexity of connecting a
module to other modules
●
A good design must have low coupling
Coupling

Object Oriented Design and Concepts related to Object Oriented Programming