0% found this document useful (0 votes)
113 views23 pages

Lesson 7 Oop Fundamentals Diit PPT Dcit 50 Oop

This document provides an overview of object-oriented programming (OOP) fundamentals. It defines key OOP concepts like classes, objects, encapsulation, inheritance, and polymorphism. It explains that classes act as blueprints for objects, and that objects contain attributes and methods. The document also outlines several advantages of OOP like reusability, modularity, extensibility, and reduced complexity.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
113 views23 pages

Lesson 7 Oop Fundamentals Diit PPT Dcit 50 Oop

This document provides an overview of object-oriented programming (OOP) fundamentals. It defines key OOP concepts like classes, objects, encapsulation, inheritance, and polymorphism. It explains that classes act as blueprints for objects, and that objects contain attributes and methods. The document also outlines several advantages of OOP like reusability, modularity, extensibility, and reduced complexity.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

Department of Industrial and

Information Technology

DCIT 50: Object Oriented Programming

LESSON
OOP Fundamentals

Prepared:

NATHANAEL F. BUENO
Department of Industrial and
Information Technology

Content
• Concept of OOP
• Importance of OOP in software development
• Defining a class and creating objects of the class
Department of Industrial and
Information Technology

What is OOP?
Object-oriented is a combination of two terms, object and
oriented.

Object - an entity that exists in the real world


Oriented - interested in a particular kind of thing
or entity
Department of Industrial and
Information Technology

What is OOP?
Object-oriented programming (OOP) is a
programming paradigm that uses objects and their interactions
to design applications and computer programs.
OOP is interested in and organized in the creation of
objects.
Department of Industrial and
Information Technology

Object-oriented Programming
Object-oriented programming has several advantages:
• OOP is faster and easier to execute
• OOP provides a clear structure for the programs
• OOP helps to keep the Java code DRY "Don't Repeat Yourself", and makes
the code easier to maintain, modify and debug
• OOP makes it possible to create full reusable applications with less code and
shorter development time
Department of Industrial and
Information Technology

Object-oriented Programming
Object-oriented programming has several advantages:

Tip: The "Don't Repeat Yourself" (DRY) principle is about reducing the
repetition of code. You should extract out the codes that are common for the
application, and place them at a single place and reuse them instead of repeating
it.
Department of Industrial and
Information Technology

Why Object Oriented Approach


A major factor in the invention of Object-Oriented approach is to
remove some of the flaws encountered with the procedural approach. In OOP,
data is treated as a critical element and does not allow it to flow freely. It
bounds data closely to the functions that operate on it and protects it from
accidental modification from outside functions. OOP allows decomposition of
a problem into a number of entities called objects and then builds data and
functions around these objects. A major advantage of OOP is code reusability.
Department of Industrial and
Information Technology

Important features of Object Oriented programming


• Emphasis on data rather than procedure
• Programs are divided into Objects
• Data is hidden and cannot be accessed by external functions
• Objects can communicate with each other through functions
• New data and functions can be easily added whenever necessary
• Follows bottom-up approach
Department of Industrial and
Information Technology

Object-oriented Approach
The Object-Oriented Approach involves designing and implementing software
systems by modeling them as collections of interacting objects. It focuses on
encapsulation, inheritance, and polymorphism to create modular, maintainable, and
extensible code.
Key Concepts of Object-oriented Programming:
• Objects
• Classes
• Data Abstraction and Encapsulation
• Inheritance
• Polymorphism
Department of Industrial and
Information Technology

Classes and Objects


Classes
Class is a collection of objects of similar type. Once a class is defined,
any number of objects can be created which belong to that class.
• Classes in OOP are like blueprints for building objects. They define the features
and functions shared by all objects of that type, like attributes (data) and
methods (behavior).
Department of Industrial and
Information Technology

Classes and Objects


Objects
Objects are the basic run-time entities in an object-oriented system. When
a program is executed, objects interact with each other by sending messages.
Different objects can also interact with each other without knowing the details of
their data or code.

Objects: Instances of a class, with specific values for their attributes and
functionality provided by their methods.
Department of Industrial and
Information Technology

Classes and Objects


Example
CLASSES OBJECTS
Mazda
Silver, Mazda, CX-5, 2024, 5 doors, gasoline engine, 16-gallon fuel tank

Car Honda
Blue, Honda, Accord, 2022, 2 doors, electric engine, 90 kWh battery
Attributes: Color, Make, Model, Year, Number
of doors, Engine type, Fuel capacity
Methods: Start(),Accelerate(),Brake() ,Turn() Mitsubishi
Black, Mitsubishi, Outlander, 2023, 4 doors, plug-in hybrid engine, 12-
gallon fuel tank
Toyota
Red, Toyota, Camry, 2023, 4 doors, hybrid engine, 15-gallon fuel tank
Department of Industrial and
Information Technology

Classes and Objects


Methods and Attributes
Methods
• Describe the behavior of an object
• These are functions that are defined inside a class that describe the
behavior of an object.
Attribute
• Represent the state of an object
• These are defined in the class template and represent the state of an
object. Objects contain data stored in the attribute field.
Department of Industrial and
Information Technology

Classes and Objects


Take note:

• You can create as many objects as you want for a class.


• A class is a template for objects, and an object is an instance of a class.
• When the individual objects are created, they inherit all the variables and methods
from the class.

Tip. A class is not an object. The object is the actual component of programs, while
the class specifies how instances are created and how they behave.
Department of Industrial and
Information Technology

Concepts of OOP
Data Abstraction
• Abstraction refers to the act of representing essential features without including
the background details or explanations. In OOP, Classes use the concept of
abstraction and are defined as a list of abstract attributes.
• Abstraction focuses on what an object does rather than how it does it, providing a
high-level view of functionality.

Abstraction: reduces code complexity, enhances code readability, and facilitates


easier understanding of the overall system.
Department of Industrial and
Information Technology

Concepts of OOP
Encapsulation
• Storing data and functions in a single unit (class) is encapsulation. Data cannot be
accessible to the outside world and only those functions which are stored in the class
can access it.
• Encapsulation involves bundling data (attributes) and the methods (functions) that
operate on that data into a single unit, known as a class.

Encapsulation: Improved security, code organization, and maintenance. Changes to the


internal workings of an object do not affect the external code using it.
Department of Industrial and
Information Technology

Concepts of OOP
Inheritance
• Inheritance is the process by which objects can acquire the properties of objects of other class.
• In OOP, inheritance provides reusability, like, adding additional features to an existing class without
modifying it. This is achieved by deriving a new class from the existing one. The new class will have
combined features of both the classes.
 It describes the ability to create new classes based on an existing class.

Inheritance: Reduces redundancy, allows for the creation of specialized classes, and simplifies code
maintenance.
Department of Industrial and
Information Technology

Concepts of OOP
Polymorphism
• Polymorphism means "many forms." In OOP, polymorphism allows objects of different types to be
treated as instances of a common base type.
• It is the ability to take more than one form. An operation may exhibit different behaviors in different
instances. The behavior depends on the data types used in the operation.
• Polymorphism is extensively used in implementing Inheritance.
 this means that you can have multiple classes that can be used interchangeably, even though
each class implements the same properties or methods in different ways.
Polymorphism: Easier code maintenance, extensibility, and improved code readability. Allows for the
use of a single interface to represent various types.
Department of Industrial and
Information Technology

Advantages of OOP
Through the establishment of sets of classes that symbolize and encapsulate objects within a program,
Object-Oriented Programming (OOP) has the capacity to systematically arrange classes into modules, thereby
enhancing the overall structural integrity of software programs.
• Reusable code: The Object-Oriented Programming (OOP) inheritance principle enables the reuse of code,
eliminating the need for repetitive coding and reducing the likelihood of errors during code creation.
• Improved efficiency: Developing new software becomes more time-efficient by generating objects from
classes. Leveraging libraries and reusable code further enhances productivity.
• Augmented security: Utilizing encapsulation and abstraction allows for the presentation of restricted data
while safeguarding sensitive information. These features contribute to heightened security when dealing
with intricate code.
Department of Industrial and
Information Technology

Access Keywords
Access keywords define the access to class members from the same class and from other classes.
 Access Modifiers are keywords used to specify the declared accessibility of a member of a type.

Common Access Keywords:


• Public: Allows access to the class member from any other class.
• Private: Allows access to the class member only in the same class.
• Protected: Allows access to the class member only within the same class and from inherited classes.
• Internal: Allows access to the class member only in the same assembly.
• Protected internal: Allows access to the class member only within the same class, from inherited
classes, and other classes in the same assembly.
• Static: Indicates that the member can be called without first instantiating the class
Department of Industrial and
Information Technology

Classes
In java, the unit of programming is the class which objects are instantiated (created).
• A class provides the definition for a particular type of object
• Note. There is only one copy of a class definition in program, but there can be several objects that
are instances of that class

A class header has 3 parts The body of a class consists of


• An optional access modifier • Instance variables
• The keyword class • Methods
• Any legal identifier for classname • which is enclosed with a set of curly braces {}
Tip. Class name should be in PascalCase (first letter in a word is capital (e.g. CustomerData, OrderInformation).
Department of Industrial and
Information Technology

Classes
Import statement for JOptionPane to work

Class header

Instance variable

method

method

method
Department of Industrial and
Information Technology

Objects
How to create objects
• the new operator is used to create an object of a class
• the new operator dynamically allocates memory for an object and return a reference to it. The
reference is the address in memory of the object allocated by new. This reference is then stored in
the variable.

You might also like