You are on page 1of 34

Object-Oriented Concepts

Before we GO…
• The acts of the mind, wherein it exerts its power over
simple ideas, are chiefly these three:
1. Combining several simple ideas into one compound one, and
thus all complex ideas are made.
2. The second is bringing two ideas, whether simple or complex,
together, and setting them by one another so as to take a view
of them at once, without uniting them into one, by which it gets
all its ideas of relations.
3. The third is separating them from all other ideas that
accompany them in their real existence: this is called
abstraction, and thus all its general ideas are made.

2
Contents
• Programming Paradigms.
• Object-Oriented Paradigm.
• Object-Oriented Concepts.
• Exercises.

3
Programming Languages
• A programming language is a machine-readable artificial
language designed to express computations that can be
performed by a machine, particularly a computer.
• Each programming language have some form of written
specification of their syntax and semantics, since
computers require precisely defined instructions.
• They are not the same.
• There’s nothing called “the best language”.
• Languages most often characterized by their paradigm.

4
Programming Paradigm
• A programming paradigm is a fundamental style of
computer programming.
• Paradigms differ in:
– the concepts and abstractions used to represent the elements of
a program
– the steps that compose a computation.
• Examples
•Declarative •Event-Driven
•Imperative •Object-Oriented
•Functional •Aspect-Oriented
•Logic

5
Concepts or Practice?

6
Consequences!

7
Object-Oriented Paradigm
• Object-oriented programming (OOP) is a programming
paradigm that uses "Objects" and their interactions to
design applications and computer programs.
 Everything around us are objects interacting with each
others.
 Each object has a set of features, including adjectives
and verbs.
 Object-oriented paradigms is sometimes thought to be a
simulation of the real-world around us, which make it the
paradigm of choice for most application domains: GUIs,
games, business, etc.

8
Object-Oriented Paradigm2

9
Objects

10
Classes

Car Human

11
Classes2

Suzuki Man

BMW Woman

12
Abstraction & Inheritance

Car Human

BMW
Woman

Suzuki

Man

13
Object and Their Interaction

Program

14
Object and Their Interaction

Tom, hold your sweep!


Program

15
Object and Their Interaction

Tom, hold your sweep!


Program

Tom, beat jerry!

16
Object and Their Interaction

Tom.holdYourSweep()
Program

Tom.BeatJerry()

IN PROGRAMMING
17
Object and Their Interaction

Tom.holdYourSweep()
Program

message

Tom.BeatJerry()

IN PROGRAMMING
18
Object and Their Interaction

Tom.holdYourSweep()
Program

message

Tom.BeatJerry()

message

IN PROGRAMMING
19
OOP Concepts
• Class.
• Object.
• Instance.
• State.
• Method.
• Encapsulation.
• Inheritance.
• Polymorphism.

20
Class
• A class is an abstract definition of an object.
• Defines how would the object look like when created.
• The object type.
• Think of classes like the patents of actual inventions.

21
Object
• An object is the actual entity instance lives in memory
and capable of doing real operations.
• Created (instantiated) according to the abstract definition
of a class.
• Think of objects like some invention created according to
some patent.

22
Object vs. Class

• Object

• Class

23
State
• The value of an attribute (variable) of the object.
• Describes some object’s characteristics.
• Ex: Car.color = red
• Adjectives.

24
Method
• An object’s ability to do some operation.
• Implements some functionality.
• Invoked by the same object or other interacting objects
in the system.
• Ex: car.accelerate()
• Verbs.

25
Message Passing
• The process by which an object:
– Sends data to another object.
– Asks the other object to invoke a
method.
• In other words, objects talk to each
others via messages.

26
Encapsulation
• Encapsulation is hiding the functional details from the
object calling it.
• Can you drive a car?
– Yes, I can!
• So, how does acceleration work?
– Huh?
• Details encapsulated (hidden) from the driver.

27
Inheritance
• Inheritance is the process of
subclassing some class by inheriting all
of its attributes and methods.
• Parent class is called Superclass.
• Child class is called Subclass.
• Subclasses are more specialized
version of a class.

28
Inheritance (2)

• Superclass

• Subclass

29
Polymorphism
• Different objects share the same interface (e.g: same
method names).
• Different functionalities /implementations.
• One object may have several interfaces.
• One object can be treated as if it’s an instance from
several types (classes).

30
OOAD
• Object-oriented analysis and design (OOAD) is a
software engineering approach that models a system as
a group of interacting objects.
• Identifying what objects would we have in the system,
and designing them.
• Abstract Process
– Identify real entities (nouns)/ system entities.
– Design entities attributes and methods.
– Notate your design.

31
Design Patterns
• A design pattern is a formal way of documenting a
solution to a design problem in a particular field of
expertise.
• Best solutions for common problems.
• Design Patterns ("Gang-of-four book") by Erich Gamma
et al, with patterns for object-oriented programming
(software engineering).

32
UML
• The Unified/Universal Modeling Language (UML) is a
standardized visual specification language for object
modeling.
• General-purpose modeling language that includes a
graphical notation used to create an abstract model of a
system, referred to as a UML model.
• Example: Class Diagram

33
Exercises
1. Develop an object-oriented model for a goal slice of a
soccer game.
2. Develop an object-oriented model for the home-delivery
slice in a fast food restaurant.
3. Identify the objects only in a banking system.

34

You might also like