SlideShare ist ein Scribd-Unternehmen logo
1 von 12
Downloaden Sie, um offline zu lesen
Object Oriented Programming
Irfan Wahyudin, S.Si, M.Kom
Pertemuan Sebelumnya...
● Top down/bottom up Programming
● Structured Programming
● Procedural Programming
Mengapa Perlu OOP?
● Top-Down/Bottom-Up Programming→
Spaghetti Code
● Structured Programming → Tidak reusable
● Procedural Programming → Sudah reusable,
tetapi belum merepresentasikan object, belum
modular, dan hard-to-manage
Object Oriented Programming
● Untuk itu dikembangkan OOP
● Konsep dasar OOP:
– Objek
– Abstraksi
– Enkapsulasi
– Polimorfisme
– Inheritance
Enkapsulasi
● Ilustrasi...
Kenapa Butuh Enkapsulasi?
Representasi dalam Program
Class Animal{
string color;
bool canWrite;
Animal(bool _canWrite){
canRun = _canWrite;
}
void setColor(string _color){
color = _color;
}
void write(){
if (canWrite){
System.out.println(“Wow...it can write”);
}
}
}
Class AnimalTest{
public static void main(string [] Args){
Animal dog = new Animal(true);
Animal sheep = new Animal(false);
dog.write();
dog.color = “red”;
dog.setColor(“red”);
}
}
Contoh lain...
class Saving {
public class Account {
private decimal accountBalance = 5000;
private decimal registrationFee = 200;
public void deposit(decimal amount) {
amount = amount - registrationFee;
accountBalance += amount;
}
}
static void Main() {
Account myAccount = new Account();
MyAccount.accountBalance += 2000;
decimal myBalance = myAccount.deposit(2000);
}
}
Access Modifiers
● Private
● Protected
● Public
Private
●
Definition: “The type or member can be accessed only by code in
the same class or struct.”
●
Contoh:
Class Mahasiswa(){
private string nik;
private string nama;
private string getNama(){
return nama;
}
}
Class Universitas(){
public static void main(String [] args){
Mahasiswa mhs = new Mahasiswa();
System.out.print(mhs.nama);
}
}
Public
● Definition: “The type or member can be
accessed by any other code in the same
assembly or another assembly that references
it.”
Protected
● Definition: “The type or member can be
accessed only by code in the same class or
struct, or in a class that is derived from that
class.”
● Penggunaan: Lebih banyak pada kasus
turunan class (Inheritance)

Weitere ähnliche Inhalte

Ähnlich wie P 3 object_oriented_programming

Scala the good and bad parts
Scala the good and bad partsScala the good and bad parts
Scala the good and bad partsbenewu
 
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014hwilming
 
Introduction to functional programming
Introduction to functional programmingIntroduction to functional programming
Introduction to functional programmingKonrad Szydlo
 
F# in the Classroom and the Lab
F# in the Classroom and the LabF# in the Classroom and the Lab
F# in the Classroom and the LabRichard Minerich
 
Scala - the good, the bad and the very ugly
Scala - the good, the bad and the very uglyScala - the good, the bad and the very ugly
Scala - the good, the bad and the very uglyBozhidar Bozhanov
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programmingsharmisivarajah
 
Object Oriented Programming_combined.ppt.pdf
Object Oriented Programming_combined.ppt.pdfObject Oriented Programming_combined.ppt.pdf
Object Oriented Programming_combined.ppt.pdfAshutoshKumar211882
 
Fp for the oo programmer
Fp for the oo programmerFp for the oo programmer
Fp for the oo programmerShawn Button
 

Ähnlich wie P 3 object_oriented_programming (14)

Scala the good and bad parts
Scala the good and bad partsScala the good and bad parts
Scala the good and bad parts
 
Twins: OOP and FP
Twins: OOP and FPTwins: OOP and FP
Twins: OOP and FP
 
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
 
Introduction to functional programming
Introduction to functional programmingIntroduction to functional programming
Introduction to functional programming
 
F# in the Classroom and the Lab
F# in the Classroom and the LabF# in the Classroom and the Lab
F# in the Classroom and the Lab
 
Scala - the good, the bad and the very ugly
Scala - the good, the bad and the very uglyScala - the good, the bad and the very ugly
Scala - the good, the bad and the very ugly
 
Ayush oops
Ayush oopsAyush oops
Ayush oops
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
OOP
OOPOOP
OOP
 
130704798265658191
130704798265658191130704798265658191
130704798265658191
 
Object Oriented Programming_combined.ppt.pdf
Object Oriented Programming_combined.ppt.pdfObject Oriented Programming_combined.ppt.pdf
Object Oriented Programming_combined.ppt.pdf
 
Scala.js
Scala.js Scala.js
Scala.js
 
Programming with Freedom & Joy
Programming with Freedom & JoyProgramming with Freedom & Joy
Programming with Freedom & Joy
 
Fp for the oo programmer
Fp for the oo programmerFp for the oo programmer
Fp for the oo programmer
 

Kürzlich hochgeladen

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 

Kürzlich hochgeladen (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

P 3 object_oriented_programming

  • 1. Object Oriented Programming Irfan Wahyudin, S.Si, M.Kom
  • 2. Pertemuan Sebelumnya... ● Top down/bottom up Programming ● Structured Programming ● Procedural Programming
  • 3. Mengapa Perlu OOP? ● Top-Down/Bottom-Up Programming→ Spaghetti Code ● Structured Programming → Tidak reusable ● Procedural Programming → Sudah reusable, tetapi belum merepresentasikan object, belum modular, dan hard-to-manage
  • 4. Object Oriented Programming ● Untuk itu dikembangkan OOP ● Konsep dasar OOP: – Objek – Abstraksi – Enkapsulasi – Polimorfisme – Inheritance
  • 7. Representasi dalam Program Class Animal{ string color; bool canWrite; Animal(bool _canWrite){ canRun = _canWrite; } void setColor(string _color){ color = _color; } void write(){ if (canWrite){ System.out.println(“Wow...it can write”); } } } Class AnimalTest{ public static void main(string [] Args){ Animal dog = new Animal(true); Animal sheep = new Animal(false); dog.write(); dog.color = “red”; dog.setColor(“red”); } }
  • 8. Contoh lain... class Saving { public class Account { private decimal accountBalance = 5000; private decimal registrationFee = 200; public void deposit(decimal amount) { amount = amount - registrationFee; accountBalance += amount; } } static void Main() { Account myAccount = new Account(); MyAccount.accountBalance += 2000; decimal myBalance = myAccount.deposit(2000); } }
  • 9. Access Modifiers ● Private ● Protected ● Public
  • 10. Private ● Definition: “The type or member can be accessed only by code in the same class or struct.” ● Contoh: Class Mahasiswa(){ private string nik; private string nama; private string getNama(){ return nama; } } Class Universitas(){ public static void main(String [] args){ Mahasiswa mhs = new Mahasiswa(); System.out.print(mhs.nama); } }
  • 11. Public ● Definition: “The type or member can be accessed by any other code in the same assembly or another assembly that references it.”
  • 12. Protected ● Definition: “The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class.” ● Penggunaan: Lebih banyak pada kasus turunan class (Inheritance)