ITC 1233 - OBJECT ORIENTED
PROGRAMMING
INTRODUCTION TO OBJECT ORIENTATION
Ms.Nirasha Kulasooriya,
Lecturer, Dept. of ICT, FOT,USJ.
DO YOU KNOW WHAT IS SOFTWARE CRISIS?
THE SOFTWARE CRISIS
Software crisis is a term used in the early days of computer science for the
difficulty of writing useful and efficient computer programs in required time.
• Projects running over-budget
• Projects running over-time
• Inefficient and low quality software
• Software often didn’t meet requirements
• Projects were unmanageable and code was difficult to maintain
CONVENTIONAL PROGRAMMING
• Programs were sequential, running to completion
while branching and looping according to programs
instructions.
• As a program grows in size, maintenance of such
programs become complex and unimaginable.
• It can be very difficult to locate and error in a large
computer code.
DO YOU KNOW WHAT IS OBJECT ORIENTATION?
OBJECT ORIENTED PROGRAMMING
• Object oriented programming allows the programmer
to think in a different way about software and its
development.
• Modular, object oriented
design-and-implementation approach is much
more productive.
• Object-oriented programs are often easier to
understand, correct and modify.
ADVANTAGES OF OOP
• Modularity
• Provides a clear modular structure for programs.
• Decomposing a complex problem into smaller chunks or discrete components.
• Modifiability
• Re-usability
• Objects can be reused within and across applications.
• Enables faster development.
• Extensibility
• Maintainability
• Makes software easier to maintain.
DISADVANTAGES OF OOP
• Complexity
• Needs a very good knowledge in OOP to design and
implement using OOP concepts.
• Larger programs.
• Slow
• Takes longer to compile.
.
WHAT ARE THE MAIN COMPONENTS OF
OBJECT ORIENTATION?
OBJECTS
• An object is a logical unit that contains both data and
operations that manipulates it.
• Objects stems from techniques with attempting to solve
real-life events employing everyday objects.
• Objects mainly have two characteristics:
• State (data) – in Java: fields (i.e. attributes)
• Behavior (operations) – in Java: methods
EXAMPLE: OBJECTS
OBJECT: A CAR
• Car is a physical object. It has properties (attributes) like: a
colour, fuel type, transmission type etc.
• If we move the car, we change the location property. If
we paint it we change the colour property.
• When we change the attributes of a car, the fact that it is
still a car, remains the same.
CLASSES
• Objects of the same kind share many characteristics.
- e. g.: A car is just one of many cars
• A Class is simply a representation of an object. In other
words, it is the blueprint, plan or template that describes the
details of an object.
- A class is a similar concept to a car’s engineering drawings or a
house’s blueprints.
• An object is an instance of a class.
- You cannot drive a car’s engineering drawings. Before you can drive
a car, it must be built from the engineering drawings that describe it.
EXAMPLE:
CAR Car class
Object 1 Object 2 Object 3
ACTIVITY 01
• Make a group with three (03) members.
• Discuss a real world example regarding object orientation.
• Take a paper and elaborate your scenario specifying objects
and classes separately.
• And you can make any assumptions if any, please mention
those.
• Write down your index numbers in the paper.
INSTANTIATION AND REUSE
• Using a car’s engineering drawings, you can produce a
car. Similarly, the process of building an object of a class
is called instantiation. An object then is referred to as an
instance of a class.
• Just as car’s engineering drawings can be reused
many times to create many cars, you can reuse a
class many times to create many objects.
ATTRIBUTES AND INSTANCE VARIABLES
• A car has attributes, such as its colour, its number of doors, the
amount of gas in its tank, its current speed and its record of total
miles driven (i.e., its odometer reading).
• The car’s attributes are represented as part of its design in its
engineering diagrams (which, for example, include an odometer
and a fuel gauge).
• As you drive an actual car, these attributes are carried along with
the car.
METHODS
• Performing a task in a program requires a method.
• The method houses the program statements that actually perform its
tasks.
• The method hides these statements from its user, just as the accelerator
pedal of a car hides from the driver the mechanisms of making the car go
faster.
• In Java, we create a program unit called a class to house
• the set of methods that perform the class’s tasks.
MESSAGES AND METHOD CALLS
When you drive a car, pressing its gas pedal sends a
message to the car to perform a task (an operation),
that is to go faster. Similarly, each message is
implemented as a method call that tells a method of
the object to perform a task.
WHAT ARE THE CORE CONCEPTS IN OOP?
ENCAPSULATION
• Classes (and their objects) encapsulate, i.e., encase, their attributes
and methods.
• Objects may communicate with one another, but they’re normally
not allowed to know how other objects are
implemented—implementation details can be hidden within the
objects themselves.
• This information hiding, as we’ll see, is crucial to good software
engineering.
INHERITANCE
• A new class of objects can be created conveniently by Inheritance—the
new class (called the subclass) starts with the characteristics of an existing
class (called the superclass), possibly customizing them and adding
unique characteristics of its own.
• In our car analogy, the class “Car” could be seen as a subclass of the
more general class (superclass) “Vehicle”.
• More classes like: “Bus”, “Motorcycle”, “Truck”, … can start with the
characteristics of a “Vehicle” and possibly customize and add their own
characteristics.
Polymorphism
• Poly + morphism -> Many forms.
• Which allows user to performs a single action in different
ways within a program.
• Can be defined as another usage of inheritance.
• Within many classes which are related to each other by
inheritance polymorphism can be achieved.
ABSTRACTION
To use a car, a driver doesn’t necessarily need to know all the
details about the internal working of a car. A driver only needs
basic driving capabilities to work with the interface provided by
the car which has functions like: turning, accelerating, breaking
etc. Once you know how to use the this interface, you can drive
many types of cars, even though different manufacturers may
implement these functions differently.
ANY QUESTIONS?