You are on page 1of 27

1

Introduction to Object Orientation


and Java Programming – Part 1
CSE 2031 Y(3) – OOSD
Lecture 1
CSE 2031 – OOSD 2

Overview
• What is object orientation?

• Object-Oriented Origins

• Trends in Software Engineering

• Object-Oriented Concepts
CSE 2031 – OOSD 3

What is Object Orientation?


• Object-orientation is about trying to represent the
„objects‟ that we find in the real world in software.
• An approach for modeling problems using models
organized around real world concepts and entities.
• The fundamental construct is the object, which
combines both data and behaviour in a single entity.
• “object-oriented” means organizing software as a
collection of discrete objects that incorporate both
data structure and behaviour.
CSE 2031 – OOSD 4

What is an object?
• Objects are the elements through which we perceive
the world around us
• Every thing around you can be termed as an object
(Example: desk, student, lecturer, dog, car)
• Real-world objects share two characteristics: They
all have state and behavior.
▫ Example: Dogs have state (name, color, breed, hungry)
and behavior (barking, fetching, wagging tail)
• Identifying the state and behavior for real-world
objects is a great way to begin thinking in terms of
object-oriented programming.
CSE 2031 – OOSD 5

Example 1: A Rabbit Object


• You could (in a game, for example) create an
object representing a rabbit
• It would have data:
▫ How hungry it is
▫ How frightened it is
▫ Where it is
• And methods:
▫ eat, hide, run, dig
CSE 2031 – OOSD 6

Example 2: A Bank Account Object


• You could create an object representing a bank
account
• It would have data:
▫ Initial Balance
▫ Current Balance
• And methods:
▫ Withdraw money, deposit money
CSE 2031 – OOSD 7

Classwork
• List out the state and behaviour of a student
object.
CSE 2031 – OOSD 8

Object-Oriented Programming
• OOP is a method of implementation in which
programs are organized as cooperative
collection of objects, each of which represent
an instance of some class, and whose classes
are all members of a hierarchy of classes
united via inheritance relationships. [Booch]
• Example of OOP languages: Simula-67,
Smalltalk, C++, Java, PHP
CSE 2031 – OOSD 9

Object-Oriented Analysis
• OOA is a method of analysis that examines
requirements from the perspective of the
classes and objects found in the vocabulary of
the problem domain. [Booch]
CSE 2031 – OOSD 10

Object-Oriented Design
• OOD is a method of design that encompasses
the process of object-oriented decomposition
and a notation for depicting both logical
(class and object structure) and physical
(process and data flow) models of a system as
well as static and dynamic aspects of a
system. [Booch]
CSE 2031 – OOSD 11

Object-Oriented Concepts (1)


• Classes and Abstraction
▫ The Object-Oriented approach invites us to
understand the world, the problems around us in
terms of objects and classes.
▫ However, real-world problems are so complex that
when decomposing them it is necessary to consider
only views of the problem that will help us solve it.
▫ For example, consider the state of a human being.
There can be an endless list and not all of them might
be useful to us.
▫ Therefore, we need to introduce some degree of
abstraction.
CSE 2031 – OOSD 12

Object-Oriented Concepts (2)


• Classes and Abstraction
▫ Abstraction is the selective examination of certain
aspects of a problem. The goal of abstraction is to
isolate those aspects that are important and
suppress those aspects that are not important.
Many different abstractions of the same thing are
possible depending on the purpose for which they
are made. [Rumbaugh]
CSE 2031 – OOSD 13

Object-Oriented Concepts (3)


• Classes and Abstraction
▫ Booch defines an abstraction as a simplified
description or specification, of a system that
emphasizes some of the system details while
suppressing others. It denotes the essential
characteristics of an object that distinguish from all
other kinds of objects from the perspective of the
viewer.
▫ In object-oriented programming, abstractions of real-
world objects are represented by classes.
▫ Abstractions are based on data, behaviour and
relationships.
▫ Objects are distinct instances of a class.
CSE 2031 – OOSD 14

Example of object and class


• In a classroom, we have several individuals
attending the lecture
▫ Pooja – loves Indian food
▫ Rajiv– an expert in swimming
▫ Feroze – is a sports nut
▫ Fabrice– a brilliant boy
• From our perspective we see them as an
instantiation of a “Class” - Student
▫ Has a name
▫ Attends class
▫ Has a grade
▫ Completes assignments
CSE 2031 – OOSD 15

Object-Oriented Concepts (4)


Name
• Classes and Abstraction Grade
▫ A Class defines an Abstraction Attendance Record
▫ OO Abstractions are based on: CompleteAssignment()
 Data (name, Attendance)
AttendClass()
 “Attributes”
 Behaviour (completes assignments, attends class)
 “Operations/Methods”
 Relationships (student in course)
 External implementations
CSE 2031 – OOSD 16

Object-Oriented Concepts (5)


• Classes and Objects
▫ Classes define what properties will exist
▫ Objects provide distinct instances that exhibit
those properties
Class Objects
Student
Name George: Mary: Student
Student Name = “Mary”
Grade
Name = “George” Grade = “B”
Attendance Record
Grade = “A” Attendance = 95%
CompleteAssignment()
Attendance =
AttendClass() 90%
CSE 2031 – OOSD 17

Object-Oriented Concepts (6)


• Encapsulation
▫ Encapsulation (information hiding) consists of
separating the external aspects of an object, which
are accessible to other objects, from the internal
implementation details, which are hidden from
other objects.
▫ The structure of the object is hidden as well as the
implementation of all its methods. Other objects
will have no access to parts of the object, which
are encapsulated.
CSE 2031 – OOSD 18

Object-Oriented Concepts (7)


• Encapsulation
▫ In this way, the implementation of an object can
be changed without affecting the applications
using it as long as it respects the behaviour it has
to exhibit.
▫ Encapsulation prevents a program from being so
interdependent on implementation that a small
change has massive ripple effects.
CSE 2031 – OOSD 19

Object-Oriented Concepts (8)


• Encapsulation
CSE 2031 – OOSD 20

Object-Oriented Concepts (9)


• Messaging
▫ Objects interact and communicate with each other
using messages.
▫ A single object on its own is not very useful.
Usually an object appears as a component of an
application or a larger program that contains
many objects. These objects need to interact with
each other.
CSE 2031 – OOSD 21

Object-Oriented Concepts (10)


• Messaging
▫ Messages allow objects to determine
implementation rather than the sender
determining the implementation for each object.
▫ E.g. When an object A wants object B to perform
B‟s method, it sends a message to B. Sometimes B
needs some information to be able to perform the
task, and these are sent to B through parameters.
CSE 2031 – OOSD 22

Object-Oriented Concepts (11)


• Messaging

Take attendance() Take attendance()


{ {
Look at the back of each Ask each student for
student‟s hand!!! their name
} }
CSE 2031 – OOSD 23

Object-Oriented Concepts (12)


• Hierarchy
▫ Abstraction is a useful concept that allows us to
understand complex problems by defining specific
views.

▫ Encapsulation helps us manage this complexity by


hiding the inside view of our abstractions.

▫ A set of abstractions often forms a hierarchy and


by identifying these hierarchies in our design, we
greatly simplify our understanding of the problem.
CSE 2031 – OOSD 24

Object-Oriented Concepts (13)


• Hierarchy
▫ The two most basic forms of hierarchy in a
complex system are:
 Inheritance (is-a hierarchy)
 Single inheritance (Generalisation/Specialisation)
 Multiple inheritance
 Aggregation (part-of hierarchy)
 Whole - Part
 Containership
 Collection
 Group
CSE 2031 – OOSD 25

Object-Oriented Concepts (14)


• Inheritance
▫ Inheritance is the most important “is-a” hierarchy.
▫ Inheritance defines a relationship among classes,
where one class shares the structure or behaviour of
one or more classes (single or multiple inheritance)
▫ Inheritance thus represents a hierarchy of abstractions
in which a subclass inherits from one or more
superclasses.
 Example 1: A student is a Person
 Example 2: A dog is a mammal (inherits all the properties
and behaviour of a mammal)
CSE 2031 – OOSD 26

Object-Oriented Concepts (15)


• Inheritance

A hierarchy of Bicycles
CSE 2031 – OOSD 27

Questions
1. Real-world objects contain ___ and ___.
2. A software object's state is stored in ___.
3. A software object's behavior is exposed through ___.
4. Hiding internal data from the outside world, and accessing
it only through publicly exposed methods is known as data
___.
5. ___is the representation of all the essential features of an
object, which means its possible states and behaviours.
6. When we use inheritance, we have classes at the top of the
hierarchy that are known as ___ and classes at the bottom
of the hierarchy (or those which inherit from some other
class) known as ___
7. The code to be executed by an object when it is sent a
message is known variously as a ___ , or a ___ .

You might also like