Recap On Oop L2
Recap On Oop L2
Recap On Oop L2
OO Principles
OOAD
1
(Paradigm: a way of seeing and doing things)
• Object - Oriented (OO) Programming:
• Organizing software as a collection of objects with a certain state and behavior.
• A technique for system modeling. OO model consists of several
interacting objects.
• Object Oriented Design:
• Based on the identification & organization of objects.
• OO Methodology
• Construction of models
• The development of SW is a modeling process
• OO Modeling and Design
• Modeling objects based on the real world
• Using models to design independently of a programming language .
Object Oriented
Paradigm 2
• A model is an abstraction of something. The purpose is to
understand the product before developing it.
• Representation of the main functionalities of a complex
system. Non relevant details are ignored.
• Abstractions make it possible to deal with complexity
• An engineer, or a development team, cannot have a
global understanding of complex systems
What is a Model? 3
• Architects
• Tailors
• Statisticians
• Engineers
• Mechanics, Mechanics of fluid,
• Protocols,
• Electronic, microelectronic
• No exception for software! (Remember you are software
Engineers- you construct software.)
Who uses
modelling? 4
• Map showing roads
• Architectural models
• Mechanical models
Examples of
Models 5
.
Example of an OO
Model 6
• Objects
• Tshepo
• House lives-in
Tshepo House
• Car
• Tree
• Interactions
• Tshepo lives in the house
• Tshepo drives the car Car Tree
An OO model
example. 7
• People think in terms of objects.
• Objects map to real life entities. Eg person, house, car.
• Therefore, OO models are
• easy to develop
• easy to understand
Object-Orientation
- Advantages 8
• Save development time (and cost) by reusing
code
•once an object class is created it can be used in other
applications
•Objects can reuse behavior from other objects, through
inheritance
• Easier debugging
•classes can be tested independently
•reused objects have already been tested
Why OOP? 9
• An object has
• State (attributes)
• Well-defined behavior (operations/methods)
• Unique identity
• Object: Complex data type that has an identity, contains other
data types called attributes and modules of code called
operations or methods
• Some of the attributes and associated values are hidden inside the
object.
• Any object that wants to obtain or change a value associated with
other object, must do so by sending a message to one of the
objects (invoking a method).
What is an Object? 10
Illustration of an
Object
Operations (methods)
Object: man
Fields/Attributes (values)
method: Age: 35
Set_salary Salary: 10
employer friend
• Encapsulation
• Abstraction
• Polymorphism
• Inheritance
• Composition
Design Principles of
OOP 12
• Focus only on the important facts about the object at hand to
design, produce, and describe so that it can be easily used
without knowing the details of how it works.
• An abstraction focuses on the outside view of an object and
separates an object’s behavior from its implementation
• It’s a way of dealing with complexity within an application
• Principle used when using language specific classes and
functions. You just concentrate on the methods to use:
parameters & return data type
Analogy
• When you drive a car, you don’t have to know how the gasoline
and air are mixed and ignited.
• Instead you only have to know how to use the controls
• Example: Recall Abstract classes
Abstraction 13
• Craig Larman: “Encapsulation is a mechanism used to
hide the data, internal structure, and implementation
details of an object. All interaction with the object is
through a public interface of operations”
• The object only exposes what is needed to interact with it
through what is called interface
• Methods defined within the object are the once that
manage attributes of that object
• Its also called information hiding
• Interface - a named set of operations that characterize the
behavior of an object
Encapsulation 14
• Form of code reuse in which new function is obtained by
extending the implementation of an existing object
• The generalization class (the superclass) explicitly
captures the common attributes and methods
• The specialization class (the subclass) extends the
implementation with additional attributes and methods.
• Where an object/class acquires attributes of another class
Inheritance 15
Advantages:
•New implementation is easy, since most of it is inherited
•Easy to modify or extend the implementation being reused
Disadvantages:
•Breaks encapsulation, since it exposes a subclass to implementation details
of its superclass
•"White-box" reuse, since internal details of super classes are often visible to
Subclasses
•Subclasses may have to be changed if the implementation of the superclass
changes
•Implementations inherited from super classes can not be changed at run-time
Composition 17
Advantages:
•Contained objects are accessed by the containing class solely through their
Interfaces
•"Black-box" reuse, since internal details of contained objects are not visible
•Good encapsulation
•Fewer implementation dependencies
•Each class is focused on just one task
•The composition can be defined dynamically at run-time through objects
acquiring references to other objects of the same type
Disadvantages:
•Resulting systems tend to have more objects
•Interfaces must be carefully defined in order to use many different objects as
composition blocks
Pros & Cons of
Composition 18
• Ability to dynamically choose the method for an
operation at run-time or service-time depending on the
object responding to the service.
• Made possible by encapsulation and generalization
• Generalization – means of organizing class features such
that shared features reside in one class and unique features
reside in another
• Encapsulation – Means of organizing information about an
object such that interface/operations are separated from its
implementation/method
• Polymorphism therefore says that an operation could be
shared and defined in a superclass, but that the method
for that operation might be unique within each subclass.
Polymorphism 19
• OOP languages make extensive use of these techniques
• OO techniques can be used in analysis (requirements) and
as well as design
• OOA – concerned with developing requirements and
specifications expressed as an object model( population
of interacting objects) of a system. Models the problem
• OOD – concerned with developing object-oriented
models of a software/system to implement the
requirements identified during OOA. Models the solution
• This course is really about requirements modeling and
designing
21
.
Questions?????
22