[go: up one dir, main page]

0% found this document useful (0 votes)
10 views26 pages

SWC2333 Topic 1 OOP

Object-Oriented Programming (OOP) is a programming paradigm that organizes code into objects, which encapsulate data and behavior, enhancing modularity and reusability. Key characteristics of OOP include encapsulation, abstraction, inheritance, and polymorphism, which facilitate easier code maintenance and security. The benefits of OOP also encompass code reusability, reduced data redundancy, and improved productivity in software development.

Uploaded by

norhasiah akhir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views26 pages

SWC2333 Topic 1 OOP

Object-Oriented Programming (OOP) is a programming paradigm that organizes code into objects, which encapsulate data and behavior, enhancing modularity and reusability. Key characteristics of OOP include encapsulation, abstraction, inheritance, and polymorphism, which facilitate easier code maintenance and security. The benefits of OOP also encompass code reusability, reduced data redundancy, and improved productivity in software development.

Uploaded by

norhasiah akhir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

SWC2333 – OBJECT-

ORIENTED PROGRAMMING
TOPIC 1 – OBJECT ORIENTED
PROGRAMMING (OOP)

Prepared by Puan Norhasiah Mohd Akhir for Semester 1224


TOPIC CONTENT
1.1. Introduction to object
1.2. Elements of an object
1.2.1. Attributes
1.2.2. Behaviors
1.2.3. State
1.3 Characteristics of OOP: abstraction,
encapsulation, inheritance, polymorphism
1.4 Benefits of OOP

2
1.1. Introduction to object

▪ A data entity with unique characteristics and behaviors,


resembling real-life entities with states and actions.
▪ Represents an instance of a class, that allows multiple
objects from the same class to exist.
▪ OOP, conceptualized by Alan Kay in the mid-1960s and
first implemented in the SIMULA language, revolves
around these structured objects.

3
1.1. Introduction to object

4
1.1. Introduction to object

▪ An object is the fundamental unit of Object-Oriented


Programming (OOP), which prioritizes the objects
developers wish to manipulate rather than the logic
required to manipulate them.
▪ This orientation makes OOP particularly well-suited for
managing large and complex software projects.

5
1.1. Introduction to object

What is Object-Oriented Programming (OOP)?


▪ A programming paradigm based on the concept of "objects",
which can contain data in the form of fields (often known as
attributes or properties) and code in the form of procedures
(often known as methods).
▪ OOP focuses on the objects that developers want to
manipulate rather than the logic required to manipulate them,
allowing for more natural, manageable, and modular software
development.
6
1.1. Introduction to object

What is Object-Oriented Programming (OOP)? (continue)


▪ This approach is especially effective for building large,
complex systems where code reuse, scalability, and
efficiency are critical.
▪ 4 main principles of OOP are – Encapsulation,
Abstraction, Inheritance and Polymorphism

7
1.1. Introduction to object

▪ In the context of OOP, an object is an instance of a class


that encapsulates data and functionality including that
data.
▪ Objects serve as the basic building blocks of OOP
applications, embodying both the properties (data) and
behaviors (methods) relevant to the software being
developed.

8
1.1. Introduction to object

▪ Objects are created using classes, which define their


structure; once instantiated, objects operate
independently but can interact through defined
interfaces, following the principles of encapsulation and
abstraction.
▪ This setup not only facilitates more modular and scalable
application development but also enhances the
reusability and maintainability of code.
9
1.2. Elements of an object

State, properties, behavior and identity are elements of


object.
▪ State: The current values of each attribute continue to
make up an object's state. It can be of two types: Static
and Dynamic.
▪ Behavior: Behavior describes how an object behaves and
responds regarding state transitions.

10
1.2. Elements of an object

(continue)
▪ Identity: An object's identity is a quality that makes it
distinct from all other objects.
▪ Responsibility: It is the function of an object that it
performs within the system.

11
1.2. Elements of an object

An example of a Student object:


▪ State: Name, Age, Gender, Address.
▪ Behavior: Reading, Writing, Running.
▪ Identity: ID, Registration Number.
▪ Responsibility: To study and get good marks.

12
1.2. Elements of an object

What is an Attribute?
▪ An attribute refers to a data member or a property
associated with an object or a class
▪ They define the state of an object and can have different
values for different instances of the same class
▪ Attributes can be of various data types, such as integers,
strings, Booleans, or even other objects

13
1.3 Characteristics of OOP

14
1.3 Characteristics of OOP Classes and Objects
▪ A class is a template that consists of the data members or
variables and functions and defines the properties and
methods for a group of objects.
▪ The compiler does not allocate memory whenever you define a
class. Example:
You can define a class called Vehicle. Its data fields can be
vehicle_name, model_number, color, date_of_manufacture, etc.

15
1.3 Characteristics of OOP Abstraction
▪ Object Oriented Programming abstraction exposes only the
essential information of an object to the user and hides the
other details.
▪ In OOP, implement abstraction is by using classes that group
the data members and function together.
▪ Inside classes, the access specifiers are used for its members
to control how they are visible to the outside world. (public,
private, protected, and default (package-private))

16
1.3 Characteristics of OOP Inheritance
▪ Allows a class to inherit the properties and
methods of another class called the parent
class, the base class, or the super-class.
▪ The class that inherits is called the child
class or sub-class.
▪ It helps to avoid duplication of codes by
allowing code reuse as you need not define
the same methods and properties present in
a super-class in the sub-classes again. The
sub-class can simply inherit them.
17
1.3 Characteristics of OOP Polymorphism
▪ Means ‘having many forms’. In simple words, we can define
Java Polymorphism as the ability of a message to be displayed
in more than one form.
▪ Allows you to define one interface and have multiple
implementations.

18
1.3 Characteristics of OOP Encapsulation
▪ Enclosing the data/variables and the methods for manipulating the
data into a single entity called a class. It helps to hide the internal
implementation of the functions and state of the variables, promoting
abstraction.
▪ Allows you to define one interface and have multiple implementations.

19
Asiah is going to build a pot with the use
TO CONCLUDE ABOUT OOP of blocks. Blocks are a kind of
measurement units like height, radius,
& OBJECT…..
and shape by default. These properties
are there by default, which means if you
use a block, it has some dimensions
associated with it. Now, some other
crucial properties are not yet assigned,
like color, material, and price. So,
OBJECTS are nothing but pot. We build an
object by assigning values to the
properties when we need them. Blocks is
nothing but the templates of the object.
There we write how the object should
appeal (means look like) and how the
actions will take place. In Java, we call it a
class.

20
1.4 Benefits of OOP

1. Re-usability
▪ It means reusing some facilities rather than building them
again and again. This is done with the use of a class. We
can use it ‘n’ number of times as per our need.
2. Data Redundancy
▪ If a user wants a similar functionality in multiple classes,
he/she can go ahead by writing common class definitions
for similar functionalities and inherit them.
21
1.4 Benefits of OOP

3. Code Maintenance
▪ easy and time-saving to maintain and modify the
existing codes by incorporating new changes into
them.
4. Security
▪ With the use of data hiding and abstraction
mechanism, we are filtering out limited data to
exposure.

22
1.4 Benefits of OOP

5. Design Benefits
▪ Designing and fixing things easily and eliminating the risks (if any) -
better designs and fewer flaws.
6. Better productivity
▪ More work done, finishing a better program, having more inbuilt
features, and easier reading, writing and maintaining. Can stitch new
software objects to make completely new programs. A good number of
libraries with useful functions in abundance make it possible.
Read More:-
https://canvas.rku.ac.in/courses/3333/pages/benefits-of-object-
oriented-programming
23
SUMMARY

▪ OOPs is Object-Oriented Programming - a programming


paradigm that focuses on organizing code into objects, which
encapsulate data and behavior, promoting modularity and
reusability in software development.
▪ The main features of object-oriented programming are Class,
Object, Inheritance, Encapsulation, and Abstraction
Polymorphism.
▪ OOP gives some benefits include re-usability, avoid data
redundancy, easy to maintain the code and for security purposes.

24
SUMMARY
Feel free to read more:
https://www.naukri.com/code360/library/what-is-an-object-in-object-
oriented-programming-oops
https://medium.com/@saket_89496/state-property-behavior-and-
identity-explained-in-simple-words-b00b935cbf02
https://www.naukri.com/code360/library/what-are-the-features-of-
object-oriented-programming
https://www.geeksforgeeks.org/polymorphism-in-java/

25
“Object-oriented programming offers a
sustainable way to write spaghetti code. It lets
you accrete programs as a series of patches.
Large organizations always tend to develop
software this way, and I expect this to be as
true in a hundred years as it is today.”
― Paul Graham, Hackers & Painters: Big Ideas from the
Computer Age

26

You might also like