01 - Classes and Objects
01 - Classes and Objects
Programming
Week 01 – Classes and Objects
LECTURES:
• SAMUEL ADY SANJAYA
• AGUS SULAIMAN
• BUDI SITORUS
• ENRICO SISWANTO
Objectives
0 0
Review OOP vs Procedural
Procedural Oriented Programming Object-Oriented Programming
In object-oriented programming, the program is divided into small parts
In procedural programming, the program is divided into small parts called functions.
called objects.
Procedural programming follows a top-down approach. Object-oriented programming follows a bottom-up approach.
There is no access specifier in procedural programming. Object-oriented programming has access specifiers like private, public, protected, etc.
Adding new data and functions is not easy. Adding new data and function is easy.
Procedural programming does not have any proper way of hiding data so it is less
Object-oriented programming provides data hiding so it is more secure.
secure.
In procedural programming, overloading is not possible. Overloading is possible in object-oriented programming.
In procedural programming, there is no concept of data hiding and inheritance. In object-oriented programming, the concept of data hiding and inheritance is used.
In procedural programming, the function is more important than the data. In object-oriented programming, data is more important than function.
Procedural programming is based on the unreal world. Object-oriented programming is based on the real world.
Procedural programming is used for designing medium-sized programs. Object-oriented programming is used for designing large and complex programs.
Procedural programming uses the concept of procedure abstraction. Object-oriented programming uses the concept of data abstraction.
Code reusability absent in procedural programming, Code reusability present in object-oriented programming.
Examples: C, FORTRAN, Pascal, Basic, etc. Examples: C++, Java, Python, C#, etc.
Class
Definition: A class is a blueprint or
template from which objects are created. It
defines a type in terms of its data (fields or
attributes) and behavior (methods or
functions).
Memory Usage Does not occupy space in memory by itself. Occupies space in memory.
Existence Logical entity and does not exist physically. Physical entity and exists in memory.
Usage Defines properties (attributes) and behaviors (methods) Represents specific instances with actual values that
that objects of the class can have. follow the structure and behavior defined by its class.
Creation Declared once using the class keyword. Created many times using the new keyword and
constructor of its class.
class Planet { ... } Represents the concept of a planet Planet earth = new Planet("Earth", 149.6, 12742);
Example with properties like name, distance from the Sun, and Represents the Earth, a specific instance of the Planet
diameter. class.
Characteristics Cannot perform actions or hold data by itself. Can hold data in its fields and perform actions through its
methods.
Scope Defines the structure and capabilities for its objects. Has a state and behavior as defined by its class. Can
interact with other objects and classes.
What will
you Learn
in 14
Weeks?
Objectives
Objectives
Array vs Linked
List
Week 2-7 the objects will be stored in Array, Week 8-
14 the objects will be stored in Linked List
Array vs Linked List
0 0
1 2
Store Object in Array & Linked List
0
1
No differences to create object as an array or as
a linked list
Store Object in Array
0
1
Main Class, Array of Objects
Store Object in Linked List (Class) - 01
0
1
Create Linked List Class First
Store Object in Linked List (Class) - 02
0
1
Main Class, Linked List of Objects
Why Linked List?
More efficient memory usage.
Topic
Discusssion
Create a group with Choose a unique and
maximum 5 person new real-world case
per-group and transform it into an
object and class. The
lecturer will draw and
choose 2 groups to
present in front of the
class.
Thank You
Visit Us
elearning.umn.ac.id