Download presentation
Presentation is loading. Please wait.
1
Object-Oriented Programming
Lecture 05 Introduction to Object-Oriented Programming Jaeki Song
2
Outlines Characteristics of OOP Object Class Inheritance Polymorphism
3
Principles of Good Programming
Modularity Reusability Extensibility Ease of maintenance Preservation of data integrity Efficient debugging
4
Characteristics of OOP
Everything is an object A program is a bunch of objects telling each other what to do by sending messages Each object has its own memory made up of other objects Every object has a type All objects of a particular type can receive the same message
5
Object A natural “thing”
Any object can be identified, classified, and defined E.g., dog, desk, television set, bicycle Objects are key to understanding object-oriented technology Each object has a set of attributes that describe it Desk can be described in terms of its weight, color, and the material it is made of
6
Object Has a unique identity
Object knows (state) and can do (behavior) The state consists of a set of fields with current values The behavior is defined by a set of methods Change gear Methods (behavior) Variables (state) 3rd gear brake
7
Object: Message Objects interact and communicate with each other by sending message to each other changeGears (lowGear) Your car You
8
Object: Message Important benefits
An object’s behavior is expressed through its methods Message passing supports all possible interaction between objects Object don’t need to be in the same process
9
Object Combination of data and code (or methods)
The process of packaging an objects’ data together with its code is termed “data encapsulation” E.g. Car (Object) has data variables (describing the state of car including car’s engine type, its current speed, its make, and its model). A car also has methods (brake, accelate, changeGear) operating on its data
10
Object Encapsulation provides the ability to hide data “data hiding”
Objects are composed of internal (private) sections and external (public) sections Private is a combination of internal data and methods External section is often referred to as its “interface” Presents everything that the external users of the object need to know or are allowed to know
11
Class Each individual object in a class is called an instance of that class Change gear Change gear currentSpeed = 50 currentSpeed = 75 brake brake currentGear = 4 currentGear=3 MyCar YourCar
12
Class Can be created by defining all the data and associated methods for a given set of objects Provides the benefit of reusability Reuse the code of a given class many times to create new objects Each object gets its own data but shares a single set of methods with other objects in its class
13
Class Hierarchical structure Supper class vs. subclass
Every class is derived from a superclass classKeyword and classBody classKeyword-identifier, nameOfClass classBody – dataVariables (instance variables) and methods
14
Access Control The goal of class creator (those who create class) is to build a class that exposes only what’s necessary to the client programmer (the class consumers who use the class in their application) and keeps everything else hidden Class creator can change the hidden portion without worrying about the impact to anyone else Class creator can change the internal working of the class without worrying about how it will affect the client programmer Java use three boundaries public, private, and protected
15
Reusability Use an object of the class directly
Place an object of the class inside a new class “creating a member object” composition or aggregation car engine “A car has an engine”
16
Inheritance A new class can be defined which inherits all the attributes that have been defined for an existing class Inheritance provides the benefit of code reusability
17
Inheritance Take the existing class, clone it, and then make additions and modifications to the clone However, if the original class (bass or super or parent class) is changed, the modified “clone” (inherited or sub or child class) reflects those changes
18
Inheritance A super class contains all of the characteristics and behaviors that are shared among the classes derived from it Create a supper class to represent the core of your idea and derive other classes to express the different ways that this core can be realized
19
Inheritance Shape draw() erase() move() Circle Square Triangle draw()
FlipVertical() FlipHorizontal() extension
20
Polymorphism Greek words
“Multiple” and “Shape” Perform the same operation on different types of classes as long as they share a common trait Define a generic command which is implemented by a number of related classes Helps avoid complexity and redundancy
21
Polymorphism Interchangeable objects
Allows an instruction to be given to an object using a generalized, rather than a specifically detailed Two forms Method overloading Different types of information in the message being sent to an object Method overriding Dynamic binding
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.