object oriented programming - abstraction & encapsulation
TRANSCRIPT
2SC2 – OOP C# Dudy Fathan Ali S.Kom
Abstraction dan Encapsulation2SC2
Dudy Fathan Ali, S.Kom (DFA)2015
CEP - CCITFakultas 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 classYes, 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();
PublicPrivate
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 KasihDudy Fathan Ali S.Kom