You are on page 1of 34

Object-Oriented Concepts

By: Abdalla Mahmoud


Java Instructor – Database Egypt
abdalla@abdallamahmoud.com
http://www.abdallamahmoud.com
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.

John Locke, An Essay Concerning Human


Understanding (1690)

OO Concepts - Abdalla Mahmoud 2


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

OO Concepts - Abdalla Mahmoud 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.

OO Concepts - Abdalla Mahmoud 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

OO Concepts - Abdalla Mahmoud 5


Concepts or Practice?

OO Concepts - Abdalla Mahmoud 6


Consequences!

OO Concepts - Abdalla Mahmoud 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.

OO Concepts - Abdalla Mahmoud 8


Object-Oriented Paradigm2

OO Concepts - Abdalla Mahmoud 9


Objects

OO Concepts - Abdalla Mahmoud 10


Classes

Car Human

OO Concepts - Abdalla Mahmoud 11


Classes2

Suzuki Man

BMW Woman

OO Concepts - Abdalla Mahmoud 12


Abstraction & Inheritance

Car Human

BMW
Woman

Suzuki

Man

OO Concepts - Abdalla Mahmoud 13


Object and Their Interaction

Program

OO Concepts - Abdalla Mahmoud 14


Object and Their Interaction

Tom, hold your sweep!


Program

OO Concepts - Abdalla Mahmoud 15


Object and Their Interaction

Tom, hold your sweep!


Program

Tom, beat jerry!

OO Concepts - Abdalla Mahmoud 16


Object and Their Interaction

Tom.holdYourSweep()
Program

Tom.BeatJerry()

IN PROGRAMMING
OO Concepts - Abdalla Mahmoud 17
Object and Their Interaction

Tom.holdYourSweep()
Program

message

Tom.BeatJerry()

IN PROGRAMMING
OO Concepts - Abdalla Mahmoud 18
Object and Their Interaction

Tom.holdYourSweep()
Program

message

Tom.BeatJerry()

message

IN PROGRAMMING
OO Concepts - Abdalla Mahmoud 19
OOP Concepts
• Class.
• Object.
• Instance.
• State.
• Method.
• Encapsulation.
• Inheritance.
• Polymorphism.

OO Concepts - Abdalla Mahmoud 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.

OO Concepts - Abdalla Mahmoud 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.

OO Concepts - Abdalla Mahmoud 22


Object vs. Class

• Object

• Class

OO Concepts - Abdalla Mahmoud 23


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

OO Concepts - Abdalla Mahmoud 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.

OO Concepts - Abdalla Mahmoud 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.

OO Concepts - Abdalla Mahmoud 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.

OO Concepts - Abdalla Mahmoud 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.

OO Concepts - Abdalla Mahmoud 28


Inheritance (2)

• Superclass

• Subclass

OO Concepts - Abdalla Mahmoud 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).

OO Concepts - Abdalla Mahmoud 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.

OO Concepts - Abdalla Mahmoud 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).

OO Concepts - Abdalla Mahmoud 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

OO Concepts - Abdalla Mahmoud 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.

OO Concepts - Abdalla Mahmoud 34

You might also like