CS304
CS304
● Object Oriented:
○ is the technique in which we visualize our programming problems in
the form of objects and their interactions as happens in real life.
○ We move our concentration to objects in contrast to the procedural
paradigm in which we simply write our code in functions and call them
in our program.
○ A Model is an abstraction of something real or conceptual.
○ OO Models are several interacting objects to understand a system
given to us for implementation.
○ Pros of OO Models:
■ Easily developed
■ Understandable
■ Easily implemented.
○ An object is
■ something tangible
■ conceptual
■ has a:
■ state (attributes)
■ well-defined behavior (operations)
■ unique identity.
● Objects may be tangible or intangibles.
Lecture # 2
● Information hiding says that all the information should not be accessible to
all people. Only owners can access their private information.
● In OOP, objects have their attributes and behaviors hidden from other classes.
● Pros are:
○ it simplifies our OO Model.
○ It is a barrier against change propagation.
● Encapsulation means enclosing all the characteristics of an object into itself.
The data and behavior are tightly coupled inside an object and its information
structure and operational implementation details are hidden from the outer
world.
○ Pros of Encapsulations are:
■ Simplicity and clarity
■ low complexity
■ better understanding.
● Interface is a set of functions in an object that it wants to expose to other
objects.
● Implementations has two parts;
○ An internal data structure.
○ Functionality.
● Messages (Stimulus) is the communication between objects by invoking
appropriate operations on the target. The number and kind of messages
depends upon the interface of an object.
Lecture # 3
● Abstraction is a way to cope with complexity and it is used to simplify things.
● Principle of abstraction: Capture only those details about an object that are
relevant to current perspective.
● Classes or prototype or map or sketch is something we create for each kind
of object and we use these sketches to create different instances. All objects
of same kind exhibit identical characteristics however have their own data.
● Inheritance means the concept of class inheriting the characteristics from
another class. The parent class is called a base class and the child class is
called derived class. Child class may have its own unique characteristics.
● Pros of inheritance are;
○ Reuse
○ Less redundant
○ Increases maintainability
● Why inheritance? Inheriting the characteristics from one class can help
reusing the functions, characteristics, behavior and attributes. Hence reduces
the need to make duplicate functions and characteristics. For example, Both
cat and dog are mammal and have same characteristics but also have unique
characteristics. The bear a child and eat but their call are different.
Lecture # 4
● Generalization:
○ The common characteristics (attributes and behaviour) of all the
objects are combined in a single general class. Base (general) class
encapsulate the common behaviour of all derived classes. This is
known as generalizations.
● Sub-Typing (Extension):
○ Derived class is behaviourally compatible with the base class.
○ Derived class has all the characteristics of base class.
○ Behaviourally compatible means that the base class can be replaced
by a derived class.
● Specialization (Restriction):
○ Derived class is behaviourally incompatible with the base class.
○ Drive class has some different of restricted characteristics than of base
class.
● Overriding:
○ Derived class overrides the behaviour of the base class.
■ Reasons:
● Specialization: Behaviour specific.
● Extension.
● Restriction.
● Improve Performance
● Abstract Class:
○ Implements an abstract concept.
○ To be inherited by other class
○ Cannot be instantiated
○ Promotes reuse.
● Concrete Class:
○ Real world entities are called concrete concepts.
○ Concrete classes implements concrete concepts.
○ Instantiate objects.
○ Provides implementation details specific to the domain context.
Lecture # 5
● Multiple Inheritance:
○ Having more than one parent class.
○ Pros:
■ Decreases redundancy.
● Cons:
○ Complex
■ Low understandings.
■ Duplication.
● Association:
○ Interaction of different objects in OO model (or in problem domain).
■ Kinds:
● Class Association:
○ Inheritance implements generalization /
specialization relationship b/w objects. Inheritance
is considered class association.
○ Public inheritance is “IS-A” relationship.
○ Private inheritance is “Implemented in term of”
relationship.
● Object Association:
○ Interaction of stand alone objects of one class with
other objects of another class.
○ Types:
■ Simple Association:
■ Composition
■ Aggregation
○ Simple Association:
■ The two interacting objects have no intrinsic relationship with
other object. It is the weakest link b/w objects.
■ Categorized:
■ W.r.t Direction (Navigation)
■ W.r.t number of objects (Cardinality)
● Kinds of Simple Association w.r.t Navigation:
○ One-way Association.
○ Two-way Association.
● Kinds of Simple Association w.r.t Cardinality:
○ Binary Association:
■ B/w two classes.
○ Ternary Association:
■ B/w three classes.
○ N-ary Association:
■ B/w 3 or more classes.
● Composition:
○ An object may be composed of other smaller objects, the
relationship b/w the “part” objects and the “whole” objects is
known as Composition.
○ It is a stronger relationship.
○ Is a part of the composer.
○ Cannot exist independently.
● Aggregation:
○ Object may contain a collection of other object, the relationship
between the container and the contained object is called
aggregation.
○ It is a weaker relationship.
○ it is not a part of a container.
○ Can exist independently.
Lecture # 6
● Class Compatibility:
○ A class is behaviourally compatible with each other if it supports all the
operations of the other class. Such a class is called subtype.
○ A class can be replaced by its subtype.
○ Derived class is usually a subtype of base class.
● Polymorphism:
○ Different forms of single entity is called polymorphism.
○ Different objects can behave in different ways for the same messages
(stimulus).
○ Advantages:
■ Flexible.
■ Reusable.
■ New classes can be added without changing the existing model.
Lecture # 7
● Class