KEMBAR78
Object Oriented Programming - Abstraction & Encapsulation | PPTX
2SC2 – OOP C# Dudy Fathan Ali S.Kom
Abstraction dan Encapsulation
2SC2
Dudy Fathan Ali, S.Kom (DFA)
2015
CEP - CCIT
Fakultas Teknik Universitas Indonesia
Abstraction
2SC2 – OOP C# Dudy Fathan Ali S.Kom
You are the salesman, please help the customer..
Hey, I need a
Car.
Abstraction
2SC2 – OOP C# Dudy Fathan Ali S.Kom
Hey, I need a
Car.
You are the salesman, please help the customer..
Abstraction
2SC2 – OOP C# Dudy Fathan Ali S.Kom
Abstraction involves extracting only the relevant
information.
Courseware NIIT – Object Oriented Programming Using C# - 1
Abstraction
2SC2 – OOP C# Dudy Fathan Ali S.Kom
In a programmer’s perspective..
Display
Car
Insert
Car
Class
Car
I want to
Display the Car
Delete
Car
Just because the user want to display it, doesn’t
mean insert and delete function is unavailable.
Encapsulation
2SC2 – OOP C# Dudy Fathan Ali S.Kom
Encapsulation, in the context of C#, refers to an object's ability to hide
data and behavior that are not necessary to its user.
www.techopedia.com
Private -
Employee’s
Salary
I want to
access ID
Employee
Yes, because
it’s Public
Public –
Name, ID of
Employee
Cashier
Human Resources
Database
Human Resources
Database
Encapsulation
2SC2 – OOP C# Dudy Fathan Ali S.Kom
Encapsulation, in the context of C#, refers to an object's ability to hide
data and behavior that are not necessary to its user.
www.techopedia.com
Private -
Employee’s
Salary
Public –
Name, ID of
Employee
I want to
access my
friend’s salary
No, because it’s
private!! It
doesn’t
belongs to
cashier.
Cashier
Human Resources
Database
Encapsulation
2SC2 – OOP C# Dudy Fathan Ali S.Kom
Encapsulation, in the context of C#, refers to an object's ability to hide
data and behavior that are not necessary to its user.
www.techopedia.com
Private -
Employee’s
Salary
Public –
Name, ID of
EmployeeHRD Manager
I want to
access my
friend’s salary
Yes, because this
data is belongs to
him
Yes, because this
data is belongs to
him and also it’s
public
Encapsulation
2SC2 – OOP C# Dudy Fathan Ali S.Kom
In a programmer’s perspective..
Private –
Employee’s
Salary
Public –
Name, ID of
Employee
Access to all code in
the program
Class HR_Data
Access to only
members of the
same class
Yes, same
class!
method
method
Private
Encapsulation – Access Specifier
2SC2 – OOP C# Dudy Fathan Ali S.Kom
Encapsulation, in the context of C#, refers to an object's ability to hide
data and behavior that are not necessary to its user.
www.techopedia.com
Public Protected
Internal
Protected
Internal
Access
Specifier
Encapsulation – Access Specifier
2SC2 – OOP C# Dudy Fathan Ali S.Kom
Encapsulation, in the context of C#, refers to an object's ability to hide
data and behavior that are not necessary to its user.
www.techopedia.com
Encapsulation – Access Specifier
2SC2 – OOP C# Dudy Fathan Ali S.Kom
Encapsulation, in the context of C#, refers to an object's ability to hide
data and behavior that are not necessary to its user.
www.techopedia.com
Class DisplayData
{
public void Method1()
{
Console.WriteLine(“Public”);
Method2();
}
private void Method2()
{
Console.WriteLine(“Private”);
}
}
Output :
Class Program :
DisplayData dd = new
DisplayData();
dd.Method1();
Public
Private
Access Specifier
Encapsulation – Access Specifier
2SC2 – OOP C# Dudy Fathan Ali S.Kom
Encapsulation, in the context of C#, refers to an object's ability to hide
data and behavior that are not necessary to its user.
www.techopedia.com
Class DisplayData
{
public void Method1()
{
Console.WriteLine(“Public”);
Method2();
}
private void Method2()
{
Console.WriteLine(“Private”);
}
}
Output :
Error!! Because method2()
has a private access.
Class Program :
DisplayData dd = new
DisplayData();
dd.Method2();
Access Specifier
3SC4 PNJ – Q5 Dudy Fathan Ali S.Kom
Terima Kasih
Dudy Fathan Ali S.Kom
dudy.fathan@eng.ui.ac.id

Object Oriented Programming - Abstraction & Encapsulation

  • 1.
    2SC2 – OOPC# Dudy Fathan Ali S.Kom Abstraction dan Encapsulation 2SC2 Dudy Fathan Ali, S.Kom (DFA) 2015 CEP - CCIT Fakultas Teknik Universitas Indonesia
  • 2.
    Abstraction 2SC2 – OOPC# Dudy Fathan Ali S.Kom You are the salesman, please help the customer.. Hey, I need a Car.
  • 3.
    Abstraction 2SC2 – OOPC# Dudy Fathan Ali S.Kom Hey, I need a Car. You are the salesman, please help the customer..
  • 4.
    Abstraction 2SC2 – OOPC# Dudy Fathan Ali S.Kom Abstraction involves extracting only the relevant information. Courseware NIIT – Object Oriented Programming Using C# - 1
  • 5.
    Abstraction 2SC2 – OOPC# Dudy Fathan Ali S.Kom In a programmer’s perspective.. Display Car Insert Car Class Car I want to Display the Car Delete Car Just because the user want to display it, doesn’t mean insert and delete function is unavailable.
  • 6.
    Encapsulation 2SC2 – OOPC# Dudy Fathan Ali S.Kom Encapsulation, in the context of C#, refers to an object's ability to hide data and behavior that are not necessary to its user. www.techopedia.com Private - Employee’s Salary I want to access ID Employee Yes, because it’s Public Public – Name, ID of Employee Cashier Human Resources Database
  • 7.
    Human Resources Database Encapsulation 2SC2 –OOP C# Dudy Fathan Ali S.Kom Encapsulation, in the context of C#, refers to an object's ability to hide data and behavior that are not necessary to its user. www.techopedia.com Private - Employee’s Salary Public – Name, ID of Employee I want to access my friend’s salary No, because it’s private!! It doesn’t belongs to cashier. Cashier
  • 8.
    Human Resources Database Encapsulation 2SC2 –OOP C# Dudy Fathan Ali S.Kom Encapsulation, in the context of C#, refers to an object's ability to hide data and behavior that are not necessary to its user. www.techopedia.com Private - Employee’s Salary Public – Name, ID of EmployeeHRD Manager I want to access my friend’s salary Yes, because this data is belongs to him Yes, because this data is belongs to him and also it’s public
  • 9.
    Encapsulation 2SC2 – OOPC# Dudy Fathan Ali S.Kom In a programmer’s perspective.. Private – Employee’s Salary Public – Name, ID of Employee Access to all code in the program Class HR_Data Access to only members of the same class Yes, same class! method method
  • 10.
    Private Encapsulation – AccessSpecifier 2SC2 – OOP C# Dudy Fathan Ali S.Kom Encapsulation, in the context of C#, refers to an object's ability to hide data and behavior that are not necessary to its user. www.techopedia.com Public Protected Internal Protected Internal Access Specifier
  • 11.
    Encapsulation – AccessSpecifier 2SC2 – OOP C# Dudy Fathan Ali S.Kom Encapsulation, in the context of C#, refers to an object's ability to hide data and behavior that are not necessary to its user. www.techopedia.com
  • 12.
    Encapsulation – AccessSpecifier 2SC2 – OOP C# Dudy Fathan Ali S.Kom Encapsulation, in the context of C#, refers to an object's ability to hide data and behavior that are not necessary to its user. www.techopedia.com Class DisplayData { public void Method1() { Console.WriteLine(“Public”); Method2(); } private void Method2() { Console.WriteLine(“Private”); } } Output : Class Program : DisplayData dd = new DisplayData(); dd.Method1(); Public Private Access Specifier
  • 13.
    Encapsulation – AccessSpecifier 2SC2 – OOP C# Dudy Fathan Ali S.Kom Encapsulation, in the context of C#, refers to an object's ability to hide data and behavior that are not necessary to its user. www.techopedia.com Class DisplayData { public void Method1() { Console.WriteLine(“Public”); Method2(); } private void Method2() { Console.WriteLine(“Private”); } } Output : Error!! Because method2() has a private access. Class Program : DisplayData dd = new DisplayData(); dd.Method2(); Access Specifier
  • 14.
    3SC4 PNJ –Q5 Dudy Fathan Ali S.Kom Terima Kasih Dudy Fathan Ali S.Kom dudy.fathan@eng.ui.ac.id