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

Lecture4 - OOP in Python - Building Blocks

The document discusses Object-Oriented Programming (OOP) in Python, outlining its fundamental building blocks: classes, attributes, methods, and objects. It highlights the advantages of OOP, such as improved code structure, modularity, readability, and maintainability. Additionally, it compares Python with other programming languages like Java, C++, and C# in the context of OOP.

Uploaded by

Maringka Raissa
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 views25 pages

Lecture4 - OOP in Python - Building Blocks

The document discusses Object-Oriented Programming (OOP) in Python, outlining its fundamental building blocks: classes, attributes, methods, and objects. It highlights the advantages of OOP, such as improved code structure, modularity, readability, and maintainability. Additionally, it compares Python with other programming languages like Java, C++, and C# in the context of OOP.

Uploaded by

Maringka Raissa
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

Fakultas Ilmu Komputer

Learning is the process of acquiring new


understanding, knowledge, behaviors, skills,
values, attitudes, and preferences.

OOP in Python – Building Blocks


4 Best Object-
Oriented
Programming
Languages
4 Best OOP Languages

[1] Python is an interpreted, high-level, general-purpose


programming language. Developers choose Python for a
variety of use cases. Python applications range from game
development to data science and machine learning.
4 Best OOP Languages

[2] As a class-based programming language, Java is designed to


have few dependencies; thus, Java developers can look forward
to uninterrupted reusability.
4 Best OOP Languages

C++, or ‘C with Classes’ is an object-oriented extension of C. C is a


classic programming language that still ranks high in the TIOBE
Index today. Yet its extension C++ performs exceptionally well when
working with embedded systems like smartwatches and medical
machines.
4 Best OOP Languages

C# is a language of the .NET framework, a product of Microsoft


that guides developers in building applications. Like C++, C# is
also a middleware language that can work closely with
hardware. C# is primarily used for game development in Unity.
1 - Basic principles (building blocks)
of OOP (object oriented programming)
"OOP in Python – Building Blocks" dapat diartikan sebagai konsep dasar
pemrograman berorientasi objek (OOP) dalam bahasa pemrograman Python,
dengan fokus pada elemen-elemen atau blok pembangunan utamanya. Dalam hal
ini, "building blocks" mengacu pada basic concepts yang membentuk dasar
pemrograman berorientasi objek di Python.
Basic Principles (Building Blocks)
Jika kita menggambarkan sesuatu
sebagai "building blocks", maka
maksudnya adalah salah satu
bagian terpisah yang
digabungkan untuk membuat
benda (to make a thing).

Object-oriented programming
defines a mode (style) of
programming that orients itself
around structural objects with
related properties (variables and
methods).
What is Object-Oriented Programming?
 Object-oriented programming (OOP) is a programming paradigm that uses the
concept of objects to construct well-defined, manipulable pieces of code.

 A programming paradigm describes the way in which a program is


organized. Before the emergence of OOP, procedural and structural programming
were the principal programming paradigms of the time.

 Procedural programming operates via step-by-step instructions. Structured


programming is a bit more complex, utilizing control flows like if/then/else
statements and while/for loops.

 However, object-oriented programming exerts the most leverage in a programming


environment. With object-orienting programming, we can generate a car class
and code specificities of the object inside the class.
What is Object-Oriented Programming?

With object-orienting programming, we can generate a car class and


code specificities of the object inside the class. Integral to the core of
object-oriented programming is the manipulation of objects. Objects
contain data and code which hold properties, procedures, and
functions.
2 - Four Fundamental
Building Blocks of OOP
4 Fundamental Building Blocks of OOP

Four fundamental building


blocks (Basic Principles )
cover/encompass how
object-oriented
programming works:

classes,

attributes,

methods, and

objects.
[1] Classes
 Classes offer templates to better characterize objects. In effect,
classes serve as blueprints for generating objects.

 Within a class, programmers must define the variables and


methods that its corresponding objects can reference.
 Given the car example, a class would denote the properties of the car object,
encase the car’s functionality, as well as declare the car as a class in the first
place.
Class Bundles: Behavior & State

[1] The word behavior is identical


to function – it is a piece of code that
does something (or implements a
behavior).

[2] The word state/attribute is


identical to variables – it is a
place to store values within a
class.

When we assert a class behavior and state together, it


means that a class packages functions and variables.
[2] Attributes
 Attributes (or variables) refer to the
characteristics of the object. Appearance,
state, and other qualitative traits are common
object attributes.

 Class attributes in combination with object


instances differentiate objects from one
another.

The following program demonstrates a class


declaration in Python:class Car:

def init(self, color, type):


[Link] = color;
[Link] = type;
Keyword “ self ” represents an instance of
the class for future referencing of the
object’s attributes and methods. and ‘color’
and ‘type’ represent attributes of the class.
[3] Methods

Programmers must define methods alongside


attributes. Methods encapsulate functions that handle
the data and behavior of an object instance.
In a car class, a drive method might be appropriate. We can
define such a method right below the car’s attribute definitions.
[4] Objects

Objects exist alongside


classes. They are essentially
data fields with distinct
structures that the
programmer can determine.

Once we call an object, the


program creates an instance.
An instance is a specific
object generated from a class.

Object − one of the instances of the class, perform


functionality defined in the class.
Di dalam sebuah class OOP, contohnya Bahasa pemrograman PHP/Java
menggunakan “this keyword”, sedangkan Python menggunakan “self
keyword”. Kegunaannya tetap sama, yaitu digunakan untuk merujuk
pada objek saat ini dalam class OOP dan memungkinkan manipulasi
properti atau pemanggilan metode objek tersebut.
Bahasa Pemrograman Java

Jika terdapat konflik antara “nama parameter method”


dan “variabel instans”, maka "this keyword" dapat
digunakan untuk membedakan keduanya. "this keyword“ juga
dapat digunakan untuk memanggil method dari objek yang
sedang digunakan.
Four Pillars of OOP

In addition to the fundamental building blocks of


object-oriented programming, the following technical
principles are critical to any object-oriented
programming approach.
Four Pillars of OOP
Benefits of Object-Oriented Programming

What Are the


Benefits of
Object-Oriented
Programming?

Object-oriented programming is good (favorable)


because of its malleability (sifat lunak). The ability to
regard structures of code as objects in a
programming environment empowers programmers
to shape programs freely.
By understanding the basic concepts of OOP using
Python, we as students can build programs that are more
structured, modular (kemampuan untuk membagi
program menjadi bagian-bagian yang lebih kecil yang
disebut modul atau kelas), and easy to understand,
thus improving the readability (keterbacaan) and
maintainability (pemeliharaan) of the code.

You might also like