SlideShare a Scribd company logo
Essentials of Object-
Oriented Programming
Overview
 Classes and Objects
 Using Encapsulation
 C# and Object Orientation
 Defining Object-Oriented Systems
Classes and Objects
 What Is a Class?
 What Is an Object?
 Comparing Classes to Structs
 Abstraction
What Is a Class?
 For the philosopher…
 An artifact of human classification!
 Classify based on common behavior or attributes
 Agree on descriptions and names of useful classes
 Create vocabulary; we communicate; we think!
 For the object-oriented programmer…
 A named syntactic construct that describes common
behavior and attributes
 A data structure that includes both data and functions
CAR?
What Is an Object?
 An object is an instance of a class
 Objects exhibit:
 Identity: Objects are distinguishable from one another
 Behavior: Objects can perform tasks
 State: Objects store information
Comparing Classes to Structs
 A struct is a blueprint for a value
 No identity, accessible state, no added behavior
 A class is a blueprint for an object
 Identity, inaccessible state, added behavior
struct Time class BankAccount
{ {
public int hour; ...
public int minute; ...
} }
Abstraction
 Abstraction is selective ignorance
 Decide what is important and what is not
 Focus and depend on what is important
 Ignore and do not depend on what is unimportant
 Use encapsulation to enforce an abstraction
The purpose of abstraction is not to be vague,
but to create a new semantic level in which one can be absolutely precise.
Edsger Dijkstra
Using Encapsulation
 Combining Data and Methods
 Controlling Access Visibility
 Why Encapsulate?
 Object Data
 Using Static Data
 Using Static Methods
Combining Data and Methods
 Combine the data and methods in a single capsule
 The capsule boundary forms an inside and an outside
Withdraw( )
Deposit( )
balance
Withdraw( )
Deposit( )
balance
BankAccount ?
BankAccount ?
Controlling Access Visibility
 Methods are public, accessible from the outside
 Data is private, accessible only from the inside
Withdraw( )
Deposit( )
balance
Withdraw( )
Deposit( )
balance

BankAccount ?BankAccount ?
Why Encapsulate?
 Allows control
 Use of the object
is solely through the
public methods
 Allows change
 Use of the object
is unaffected if
the private data
type changes
Withdraw( )
Deposit( )
dollars 12
Withdraw( )
Deposit( )
balance 12.56
cents 56

Object Data
 Object data describes information for individual objects
 For example, each bank account has its own balance. If two
accounts have the same balance, it is only a coincidence.
Withdraw( )
Deposit( )
balance 12.56
owner "Bert"
Withdraw( )
Deposit( )
balance 12.56
owner "Fred"
Using Static Data
 Static data describes information for all objects
of a class
 For example, suppose all accounts share the same interest
rate. Storing the interest rate in every account would be a bad
idea. Why?
Withdraw( )
Deposit( )
balance 12.56
interest 7%
Withdraw( )
Deposit( )
balance 99.12
interest 7% 
Using Static Methods
 Static methods can only access static data
 A static method is called on the class, not the object
InterestRate( )
interest 7%
Withdraw( )
Deposit( )
balance 99.12
owner "Fred"
An account objectThe account class
Classes contain static data and
static methods
Objects contain object data and
object methods



C# and Object Orientation
 Hello, World Revisited
 Defining Simple Classes
 Instantiating New Objects
 Using the this Operator
 Creating Nested Classes
 Accessing Nested Classes
Hello, World Revisited
using System;
class Hello
{
public static int Main( )
{
Console.WriteLine("Hello, World");
return 0;
}
}
Defining Simple Classes
 Data and methods together inside a class
 Methods are public, data is private
class BankAccount
{
public void Withdraw(decimal amount)
{ ... }
public void Deposit(decimal amount)
{ ... }
private decimal balance;
private string name;
}
Public methods
describe
accessible
behaviour
Private fields
describe
inaccessible
state
Instantiating New Objects
 Declaring a class variable does not create an object
 Use the new operator to create an object
class Program
{
static void Main( )
{
Time now;
now.hour = 11;
BankAccount yours = new BankAccount( );
yours.Deposit(999999M);
}
}
hour
minute
now
yours ...
...
new
BankAccount
object
Using the this Keyword
 The this keyword refers to the object used to call the
method
 Useful when identifiers from different scopes clash
class BankAccount
{
...
public void SetName(string name)
{
this.name = name;
}
private string name;
}
If this statement were
name = name;
What would happen?
Creating Nested Classes
 Classes can be nested inside other classes
class Program
{
static void Main( )
{
Bank.Account yours = new Bank.Account( );
}
}
class Bank
{
... class Account { ... }
}
The full name of the nested
class includes the name of
the outer class
Accessing Nested Classes
 Nested classes can also be declared as public or private
class Bank
{
public class Account { ... }
private class AccountNumberGenerator { ... }
}
class Program
{
static void Main( )
{
Bank.Account accessible;
Bank.AccountNumberGenerator inaccessible;
}
}


Defining Object-Oriented Systems
 Inheritance
 Class Hierarchies
 Single and Multiple Inheritance
 Polymorphism
 Abstract Base Classes
 Interfaces
 Early and Late Binding
Inheritance
 Inheritance specifies an “is a kind of" relationship
 Inheritance is a class relationship
 New classes specialize existing classes
Musician
Violin
Player
Base class
Derived class
Generalization
Specialization Is this a good
example of
inheritance ?
Class Hierarchies
 Classes related by inheritance form class hierarchies
Musician
???
String
Musician
Violin???
Musical
Instrument
plays
plays
playsViolin
Player
Stringed
Instrument
Single and Multiple Inheritance
 Single inheritance: deriving from one base class
 Multiple inheritance: deriving from two or more base
classes
Stringed
Instrument
Violin
Musical
Instrument
Stringed
Instrument
Pluckable
Violin has a single direct
base class
Stringed Instrument has
two direct base classes
Polymorphism
 The method name resides in the base class
 The method implementations reside in the derived classes
String Musician
TuneYourInstrument( )
Guitar Player
TuneYourInstrument( )
Violin Player
TuneYourInstrument( )
A method with no
implementation is
called an operation
Abstract Base Classes
 Some classes exist solely to be derived from
 It makes no sense to create instances of these classes
 These classes are abstract
Stringed Musician
{ abstract }
Guitar Player
« concrete »
Violin Player
« concrete »
You can create instances
of concrete classes
You cannot create instances
of abstract classes
Interfaces
 Interfaces contain only operations, not implementation
String Musician
{ abstract }
Violin Player
« concrete »
Musician
« interface »
Nothing but operations.
You cannot create instances
of an interface.
May contain some implementation.
You cannot create instances
of an abstract class.
Must implement all inherited operations.
You can create instances
of a concrete class.
Early and Late Binding
 Normal method calls are resolved at compile time
 Polymorphic method calls are resolved at run time
Musician
« interface »
Violin Player
« concrete »
Late binding
Early binding
runtime
TuneYourInstrument( )
TuneYourInstrument( )
Review
 Classes and Objects
 Using Encapsulation
 C# and Object Orientation
 Defining Object-Oriented Systems

More Related Content

Similar to Module 6 : Essentials of Object Oriented Programming

Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
Ahmed Swilam
 
Synapseindia strcture of dotnet development part 1
Synapseindia strcture of dotnet development part 1Synapseindia strcture of dotnet development part 1
Synapseindia strcture of dotnet development part 1
Synapseindiappsdevelopment
 
Creating classes and applications in java
Creating classes and applications in javaCreating classes and applications in java
Creating classes and applications in java
Gujarat Technological University
 
Classes-and-Object.pptx
Classes-and-Object.pptxClasses-and-Object.pptx
Classes-and-Object.pptx
VishwanathanS5
 
2. oop with c++ get 410 day 2
2. oop with c++ get 410   day 22. oop with c++ get 410   day 2
2. oop with c++ get 410 day 2
Mukul kumar Neal
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
Muhammad Waqas
 
Object Oriented Design
Object Oriented DesignObject Oriented Design
Object Oriented Design
Sudarsun Santhiappan
 
Object Oriented Design
Object Oriented DesignObject Oriented Design
Object Oriented Design
Aravinth NSP
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
Greg Sohl
 
packages and interfaces
packages and interfacespackages and interfaces
packages and interfaces
madhavi patil
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
Dennis Chang
 
Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02
Getachew Ganfur
 
Advanced CPP Lecture 2- Summer School 2014 - ACA CSE IITK
Advanced CPP Lecture 2- Summer School 2014 - ACA CSE IITKAdvanced CPP Lecture 2- Summer School 2014 - ACA CSE IITK
Advanced CPP Lecture 2- Summer School 2014 - ACA CSE IITK
Pankaj Prateek
 
Java basics
Java basicsJava basics
Java basics
Shivanshu Purwar
 
Inheritance
InheritanceInheritance
Inheritance
Padma Kannan
 
Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
ssuser8347a1
 
Java 2
Java   2Java   2
Class and object
Class and objectClass and object
Class and object
prabhat kumar
 
Oops
OopsOops
Booa8 Slide 04
Booa8 Slide 04Booa8 Slide 04
Booa8 Slide 04
oswchavez
 

Similar to Module 6 : Essentials of Object Oriented Programming (20)

Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
 
Synapseindia strcture of dotnet development part 1
Synapseindia strcture of dotnet development part 1Synapseindia strcture of dotnet development part 1
Synapseindia strcture of dotnet development part 1
 
Creating classes and applications in java
Creating classes and applications in javaCreating classes and applications in java
Creating classes and applications in java
 
Classes-and-Object.pptx
Classes-and-Object.pptxClasses-and-Object.pptx
Classes-and-Object.pptx
 
2. oop with c++ get 410 day 2
2. oop with c++ get 410   day 22. oop with c++ get 410   day 2
2. oop with c++ get 410 day 2
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
 
Object Oriented Design
Object Oriented DesignObject Oriented Design
Object Oriented Design
 
Object Oriented Design
Object Oriented DesignObject Oriented Design
Object Oriented Design
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
 
packages and interfaces
packages and interfacespackages and interfaces
packages and interfaces
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
 
Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02
 
Advanced CPP Lecture 2- Summer School 2014 - ACA CSE IITK
Advanced CPP Lecture 2- Summer School 2014 - ACA CSE IITKAdvanced CPP Lecture 2- Summer School 2014 - ACA CSE IITK
Advanced CPP Lecture 2- Summer School 2014 - ACA CSE IITK
 
Java basics
Java basicsJava basics
Java basics
 
Inheritance
InheritanceInheritance
Inheritance
 
Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
 
Java 2
Java   2Java   2
Java 2
 
Class and object
Class and objectClass and object
Class and object
 
Oops
OopsOops
Oops
 
Booa8 Slide 04
Booa8 Slide 04Booa8 Slide 04
Booa8 Slide 04
 

More from Prem Kumar Badri

Module 15 attributes
Module 15 attributesModule 15 attributes
Module 15 attributes
Prem Kumar Badri
 
Module 14 properties and indexers
Module 14 properties and indexersModule 14 properties and indexers
Module 14 properties and indexers
Prem Kumar Badri
 
Module 12 aggregation, namespaces, and advanced scope
Module 12 aggregation, namespaces, and advanced scopeModule 12 aggregation, namespaces, and advanced scope
Module 12 aggregation, namespaces, and advanced scope
Prem Kumar Badri
 
Module 13 operators, delegates, and events
Module 13 operators, delegates, and eventsModule 13 operators, delegates, and events
Module 13 operators, delegates, and events
Prem Kumar Badri
 
Module 11 : Inheritance
Module 11 : InheritanceModule 11 : Inheritance
Module 11 : Inheritance
Prem Kumar Badri
 
Module 10 : creating and destroying objects
Module 10 : creating and destroying objectsModule 10 : creating and destroying objects
Module 10 : creating and destroying objects
Prem Kumar Badri
 
Module 9 : using reference type variables
Module 9 : using reference type variablesModule 9 : using reference type variables
Module 9 : using reference type variables
Prem Kumar Badri
 
Module 8 : Implementing collections and generics
Module 8 : Implementing collections and genericsModule 8 : Implementing collections and generics
Module 8 : Implementing collections and generics
Prem Kumar Badri
 
Module 7 : Arrays
Module 7 : ArraysModule 7 : Arrays
Module 7 : Arrays
Prem Kumar Badri
 
Module 5 : Statements & Exceptions
Module 5 : Statements & ExceptionsModule 5 : Statements & Exceptions
Module 5 : Statements & Exceptions
Prem Kumar Badri
 
Module 4 : methods & parameters
Module 4 : methods & parametersModule 4 : methods & parameters
Module 4 : methods & parameters
Prem Kumar Badri
 
Module 3 : using value type variables
Module 3 : using value type variablesModule 3 : using value type variables
Module 3 : using value type variables
Prem Kumar Badri
 
Module 2: Overview of c#
Module 2:  Overview of c#Module 2:  Overview of c#
Module 2: Overview of c#
Prem Kumar Badri
 
Module 1 : Overview of the Microsoft .NET Platform
Module 1 : Overview of the Microsoft .NET PlatformModule 1 : Overview of the Microsoft .NET Platform
Module 1 : Overview of the Microsoft .NET Platform
Prem Kumar Badri
 
C# Non generics collection
C# Non generics collectionC# Non generics collection
C# Non generics collection
Prem Kumar Badri
 
C# Multi threading
C# Multi threadingC# Multi threading
C# Multi threading
Prem Kumar Badri
 
C# Method overloading
C# Method overloadingC# Method overloading
C# Method overloading
Prem Kumar Badri
 
C# Inheritance
C# InheritanceC# Inheritance
C# Inheritance
Prem Kumar Badri
 
C# Generic collections
C# Generic collectionsC# Generic collections
C# Generic collections
Prem Kumar Badri
 
C# Global Assembly Cache
C# Global Assembly CacheC# Global Assembly Cache
C# Global Assembly Cache
Prem Kumar Badri
 

More from Prem Kumar Badri (20)

Module 15 attributes
Module 15 attributesModule 15 attributes
Module 15 attributes
 
Module 14 properties and indexers
Module 14 properties and indexersModule 14 properties and indexers
Module 14 properties and indexers
 
Module 12 aggregation, namespaces, and advanced scope
Module 12 aggregation, namespaces, and advanced scopeModule 12 aggregation, namespaces, and advanced scope
Module 12 aggregation, namespaces, and advanced scope
 
Module 13 operators, delegates, and events
Module 13 operators, delegates, and eventsModule 13 operators, delegates, and events
Module 13 operators, delegates, and events
 
Module 11 : Inheritance
Module 11 : InheritanceModule 11 : Inheritance
Module 11 : Inheritance
 
Module 10 : creating and destroying objects
Module 10 : creating and destroying objectsModule 10 : creating and destroying objects
Module 10 : creating and destroying objects
 
Module 9 : using reference type variables
Module 9 : using reference type variablesModule 9 : using reference type variables
Module 9 : using reference type variables
 
Module 8 : Implementing collections and generics
Module 8 : Implementing collections and genericsModule 8 : Implementing collections and generics
Module 8 : Implementing collections and generics
 
Module 7 : Arrays
Module 7 : ArraysModule 7 : Arrays
Module 7 : Arrays
 
Module 5 : Statements & Exceptions
Module 5 : Statements & ExceptionsModule 5 : Statements & Exceptions
Module 5 : Statements & Exceptions
 
Module 4 : methods & parameters
Module 4 : methods & parametersModule 4 : methods & parameters
Module 4 : methods & parameters
 
Module 3 : using value type variables
Module 3 : using value type variablesModule 3 : using value type variables
Module 3 : using value type variables
 
Module 2: Overview of c#
Module 2:  Overview of c#Module 2:  Overview of c#
Module 2: Overview of c#
 
Module 1 : Overview of the Microsoft .NET Platform
Module 1 : Overview of the Microsoft .NET PlatformModule 1 : Overview of the Microsoft .NET Platform
Module 1 : Overview of the Microsoft .NET Platform
 
C# Non generics collection
C# Non generics collectionC# Non generics collection
C# Non generics collection
 
C# Multi threading
C# Multi threadingC# Multi threading
C# Multi threading
 
C# Method overloading
C# Method overloadingC# Method overloading
C# Method overloading
 
C# Inheritance
C# InheritanceC# Inheritance
C# Inheritance
 
C# Generic collections
C# Generic collectionsC# Generic collections
C# Generic collections
 
C# Global Assembly Cache
C# Global Assembly CacheC# Global Assembly Cache
C# Global Assembly Cache
 

Recently uploaded

The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
ZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptxZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptx
dot55audits
 
Solutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptxSolutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptx
spdendr
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
สมใจ จันสุกสี
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
Krassimira Luka
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
Wahiba Chair Training & Consulting
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
MysoreMuleSoftMeetup
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Constructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective CommunicationConstructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective Communication
Chevonnese Chevers Whyte, MBA, B.Sc.
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
S. Raj Kumar
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
imrankhan141184
 
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Leena Ghag-Sakpal
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 

Recently uploaded (20)

The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
ZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptxZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptx
 
Solutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptxSolutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptx
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Constructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective CommunicationConstructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective Communication
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching AptitudeUGC NET Exam Paper 1- Unit 1:Teaching Aptitude
UGC NET Exam Paper 1- Unit 1:Teaching Aptitude
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
 
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 

Module 6 : Essentials of Object Oriented Programming

  • 2. Overview  Classes and Objects  Using Encapsulation  C# and Object Orientation  Defining Object-Oriented Systems
  • 3. Classes and Objects  What Is a Class?  What Is an Object?  Comparing Classes to Structs  Abstraction
  • 4. What Is a Class?  For the philosopher…  An artifact of human classification!  Classify based on common behavior or attributes  Agree on descriptions and names of useful classes  Create vocabulary; we communicate; we think!  For the object-oriented programmer…  A named syntactic construct that describes common behavior and attributes  A data structure that includes both data and functions CAR?
  • 5. What Is an Object?  An object is an instance of a class  Objects exhibit:  Identity: Objects are distinguishable from one another  Behavior: Objects can perform tasks  State: Objects store information
  • 6. Comparing Classes to Structs  A struct is a blueprint for a value  No identity, accessible state, no added behavior  A class is a blueprint for an object  Identity, inaccessible state, added behavior struct Time class BankAccount { { public int hour; ... public int minute; ... } }
  • 7. Abstraction  Abstraction is selective ignorance  Decide what is important and what is not  Focus and depend on what is important  Ignore and do not depend on what is unimportant  Use encapsulation to enforce an abstraction The purpose of abstraction is not to be vague, but to create a new semantic level in which one can be absolutely precise. Edsger Dijkstra
  • 8. Using Encapsulation  Combining Data and Methods  Controlling Access Visibility  Why Encapsulate?  Object Data  Using Static Data  Using Static Methods
  • 9. Combining Data and Methods  Combine the data and methods in a single capsule  The capsule boundary forms an inside and an outside Withdraw( ) Deposit( ) balance Withdraw( ) Deposit( ) balance BankAccount ? BankAccount ?
  • 10. Controlling Access Visibility  Methods are public, accessible from the outside  Data is private, accessible only from the inside Withdraw( ) Deposit( ) balance Withdraw( ) Deposit( ) balance  BankAccount ?BankAccount ?
  • 11. Why Encapsulate?  Allows control  Use of the object is solely through the public methods  Allows change  Use of the object is unaffected if the private data type changes Withdraw( ) Deposit( ) dollars 12 Withdraw( ) Deposit( ) balance 12.56 cents 56 
  • 12. Object Data  Object data describes information for individual objects  For example, each bank account has its own balance. If two accounts have the same balance, it is only a coincidence. Withdraw( ) Deposit( ) balance 12.56 owner "Bert" Withdraw( ) Deposit( ) balance 12.56 owner "Fred"
  • 13. Using Static Data  Static data describes information for all objects of a class  For example, suppose all accounts share the same interest rate. Storing the interest rate in every account would be a bad idea. Why? Withdraw( ) Deposit( ) balance 12.56 interest 7% Withdraw( ) Deposit( ) balance 99.12 interest 7% 
  • 14. Using Static Methods  Static methods can only access static data  A static method is called on the class, not the object InterestRate( ) interest 7% Withdraw( ) Deposit( ) balance 99.12 owner "Fred" An account objectThe account class Classes contain static data and static methods Objects contain object data and object methods   
  • 15. C# and Object Orientation  Hello, World Revisited  Defining Simple Classes  Instantiating New Objects  Using the this Operator  Creating Nested Classes  Accessing Nested Classes
  • 16. Hello, World Revisited using System; class Hello { public static int Main( ) { Console.WriteLine("Hello, World"); return 0; } }
  • 17. Defining Simple Classes  Data and methods together inside a class  Methods are public, data is private class BankAccount { public void Withdraw(decimal amount) { ... } public void Deposit(decimal amount) { ... } private decimal balance; private string name; } Public methods describe accessible behaviour Private fields describe inaccessible state
  • 18. Instantiating New Objects  Declaring a class variable does not create an object  Use the new operator to create an object class Program { static void Main( ) { Time now; now.hour = 11; BankAccount yours = new BankAccount( ); yours.Deposit(999999M); } } hour minute now yours ... ... new BankAccount object
  • 19. Using the this Keyword  The this keyword refers to the object used to call the method  Useful when identifiers from different scopes clash class BankAccount { ... public void SetName(string name) { this.name = name; } private string name; } If this statement were name = name; What would happen?
  • 20. Creating Nested Classes  Classes can be nested inside other classes class Program { static void Main( ) { Bank.Account yours = new Bank.Account( ); } } class Bank { ... class Account { ... } } The full name of the nested class includes the name of the outer class
  • 21. Accessing Nested Classes  Nested classes can also be declared as public or private class Bank { public class Account { ... } private class AccountNumberGenerator { ... } } class Program { static void Main( ) { Bank.Account accessible; Bank.AccountNumberGenerator inaccessible; } }  
  • 22. Defining Object-Oriented Systems  Inheritance  Class Hierarchies  Single and Multiple Inheritance  Polymorphism  Abstract Base Classes  Interfaces  Early and Late Binding
  • 23. Inheritance  Inheritance specifies an “is a kind of" relationship  Inheritance is a class relationship  New classes specialize existing classes Musician Violin Player Base class Derived class Generalization Specialization Is this a good example of inheritance ?
  • 24. Class Hierarchies  Classes related by inheritance form class hierarchies Musician ??? String Musician Violin??? Musical Instrument plays plays playsViolin Player Stringed Instrument
  • 25. Single and Multiple Inheritance  Single inheritance: deriving from one base class  Multiple inheritance: deriving from two or more base classes Stringed Instrument Violin Musical Instrument Stringed Instrument Pluckable Violin has a single direct base class Stringed Instrument has two direct base classes
  • 26. Polymorphism  The method name resides in the base class  The method implementations reside in the derived classes String Musician TuneYourInstrument( ) Guitar Player TuneYourInstrument( ) Violin Player TuneYourInstrument( ) A method with no implementation is called an operation
  • 27. Abstract Base Classes  Some classes exist solely to be derived from  It makes no sense to create instances of these classes  These classes are abstract Stringed Musician { abstract } Guitar Player « concrete » Violin Player « concrete » You can create instances of concrete classes You cannot create instances of abstract classes
  • 28. Interfaces  Interfaces contain only operations, not implementation String Musician { abstract } Violin Player « concrete » Musician « interface » Nothing but operations. You cannot create instances of an interface. May contain some implementation. You cannot create instances of an abstract class. Must implement all inherited operations. You can create instances of a concrete class.
  • 29. Early and Late Binding  Normal method calls are resolved at compile time  Polymorphic method calls are resolved at run time Musician « interface » Violin Player « concrete » Late binding Early binding runtime TuneYourInstrument( ) TuneYourInstrument( )
  • 30. Review  Classes and Objects  Using Encapsulation  C# and Object Orientation  Defining Object-Oriented Systems