SlideShare ist ein Scribd-Unternehmen logo
1 von 74
DOING IT IN CODE

SOME MORE EXAMPLES
EXAMPLE 1

ATM
The Problem


 You are required to create an ATM application
  using OOP

 Requirements:
   User can deposit money
   User can withdraw money
   User can view balance
Example #1
Creating the Class In Code

     Add a class to the project

     Provide appropriate name for the class

     Declare properties

     Property Procedures

     Create Methods

     Add constructors/destructors if needed
Creating Classes in Code

     Add a class to the project

     Provide appropriate name for the class

     Declare properties

     Declare Methods

     Create constructors as needed

     Create a destructor, if appropriate
1. Add Class to the Project
Creating Classes in Code

     Add a class to the project

     Provide appropriate name for the class

     Declare properties

     Property Procedures

     Create Methods

     Add constructors/destructors if needed
2. Provide Appropriate Name
Creating Classes in Code

     Add a class to the project

     Provide appropriate name for the class

     Declare properties

     Property Procedures

     Create Methods

     Add constructors/destructors if needed
3. Declare Properties
3. Declare Properties
Creating Classes in Code

     Add a class to the project

     Provide appropriate name for the class

     Declare properties

     Property Procedures

     Create Methods

     Add constructors/destructors if needed
4. Property Procedures




                 This property is
                   ReadOnly
Creating Classes in Code

     Add a class to the project

     Provide appropriate name for the class

     Declare properties

     Property Procedures

     Create Methods

     Add constructors/destructors if needed
3. Create Methods
5. Deposit
5. Withdraw
Creating Classes in Code

     Add a class to the project

     Provide appropriate name for the class

     Declare properties

     Property Procedures

     Create Methods

     Add constructors/destructors if needed
EXAMPLE 2

BANK ACCOUNT
Declare properties

Property Procedures

Create Methods

Add constructors/destructors if needed
1.Declare Properties
Declare properties

Property Procedures

Create Methods

Add constructors/destructors if needed
2. _name


           Retrieve Value




           Store Value
2. _balance
2. _MaximumWithdrawal
Static (Shared) Members
 Data and behaviours that pertain to class as a
  whole
 Not just an individual instance of a class
 You can access static members even if no
  class exists
2. Shared _Rate
Declare properties

Property Procedures

Create Methods

Add constructors/destructors if needed
Deposit()
Overloading Methods
 A method might need different parameter in
  different circumstances
   The solution is to define overloaded methods
 Methods have the same name – common
  intent
 Each method can have a unique signature
 In previous example method takes parameter
  as a decimal number
Deposit ()
Overloading Methods
 The overloaded method had the same name
 The parameter list was different
 Accepts an amount as a String (text)
   Converts it to a decimal
Withdraw ()
CalculateInterest()
IncreaseRate ()
Declare properties

Property Procedures

Create Methods

Add constructors/destructors if needed
4. Overloading Constructors
In Use

Dim account as New _
 BankAccount()
Overloading Constructors
In Use

Dim account as New _
 BankAccount(“Joe”)
Overloading Constructors
In Use

Dim account as New _
 BankAccount(“Joe”, 1000)
4. Overriding Destructor
Using the Class
Instantiating the Object
Create Object
Withdrawing Cash
Method




         InputBox
Withdrawing Cash
Method
Depositing Cash
Calculate Interest
Method




         Val(txtRate.Text) / 100).ToString( "C"))
Extending our Example
Advanced OOP
Accessibility Levels
Access Level                 Visual Basic Access Modifier

Unrestricted accessibility   Public

Accessible by containing     Private
class
Accessible in current        Friend
assembly
Accessible by containing     Protected
class and derived class

Accessible in current        Protected Friend
assembly and by derived
classes
Inheritance

 Advantages
   Developer Productivity
   Real-world modelling
   Consistency
Base class




Derived Classes
Inheritance

 A base class can define overridable methods
  and properties
   Base class provides the default implementation
   Derived class provides alternative
    implementations
 A derived class can:
   Inherit base class members
   Override base class members
   Shadow base class members
Polymorphism enables an application to use instances of
derived classes interchangeably


                                 Deposit   A SavingsAccount
     Client
   application
                                 Deposit    A CheckingAccount


Benefits of polymorphism:
  Consistency and simplicity
  Extensibility and resilience
Base Class Properties
Base Class Properties
Base Class Properties
Base Class Methods
Base Class Methods
Derived Class
Derived Class
Derived Class
Shadowing

 To indicate a derived class member shadows
  a base class member
   Use the Shadows Keyword
Example
Public Class BankAccount
 Protected ReadOnly Property _
    Balance() As Decimal
 End Property

Public Class SavingsAccount
Public Shadows Sub Balance( _
    ByVal amount As Decimal)
 „Implementation
End Sub
Combining and Overloading
Combining and Overloading
Implement the Class

Weitere ähnliche Inhalte

Was ist angesagt?

C# Summer course - Lecture 1
C# Summer course - Lecture 1C# Summer course - Lecture 1
C# Summer course - Lecture 1mohamedsamyali
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming ConceptsBhushan Nagaraj
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++Vineeta Garg
 
Java oops and fundamentals
Java oops and fundamentalsJava oops and fundamentals
Java oops and fundamentalsjavaease
 
Inheritance in oops
Inheritance in oopsInheritance in oops
Inheritance in oopsHirra Sultan
 
Beginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHPBeginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHPRick Ogden
 
Class as the basis of all computation
Class as the basis of all computationClass as the basis of all computation
Class as the basis of all computationabhijeetkumarkar422
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in phpCPD INDIA
 
Oops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaOops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaMadishetty Prathibha
 
Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)indiangarg
 
Introduction to Inheritance
Introduction to InheritanceIntroduction to Inheritance
Introduction to InheritanceKeshav Vaswani
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Javabackdoor
 

Was ist angesagt? (19)

C# Summer course - Lecture 1
C# Summer course - Lecture 1C# Summer course - Lecture 1
C# Summer course - Lecture 1
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 
OOPS Characteristics (With Examples in PHP)
OOPS Characteristics (With Examples in PHP)OOPS Characteristics (With Examples in PHP)
OOPS Characteristics (With Examples in PHP)
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Java oops and fundamentals
Java oops and fundamentalsJava oops and fundamentals
Java oops and fundamentals
 
Inheritance in oops
Inheritance in oopsInheritance in oops
Inheritance in oops
 
Beginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHPBeginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHP
 
OOP Inheritance
OOP InheritanceOOP Inheritance
OOP Inheritance
 
Single inheritance
Single inheritanceSingle inheritance
Single inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
OOPS in Java
OOPS in JavaOOPS in Java
OOPS in Java
 
Class as the basis of all computation
Class as the basis of all computationClass as the basis of all computation
Class as the basis of all computation
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in php
 
Oops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in JavaOops concepts || Object Oriented Programming Concepts in Java
Oops concepts || Object Oriented Programming Concepts in Java
 
Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)
 
Inheritance in OOPS
Inheritance in OOPSInheritance in OOPS
Inheritance in OOPS
 
Introduction to Inheritance
Introduction to InheritanceIntroduction to Inheritance
Introduction to Inheritance
 
OOPs in Java
OOPs in JavaOOPs in Java
OOPs in Java
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 

Andere mochten auch

Is2215 lecture8 relational_databases
Is2215 lecture8 relational_databasesIs2215 lecture8 relational_databases
Is2215 lecture8 relational_databasesdannygriff1
 
Is2215 lecture5 lecturer_g_cand_classlibraries
Is2215 lecture5 lecturer_g_cand_classlibrariesIs2215 lecture5 lecturer_g_cand_classlibraries
Is2215 lecture5 lecturer_g_cand_classlibrariesdannygriff1
 
Is2215 lecture6 lecturer_file_access
Is2215 lecture6 lecturer_file_accessIs2215 lecture6 lecturer_file_access
Is2215 lecture6 lecturer_file_accessdannygriff1
 
Stocks&bonds2214 1
Stocks&bonds2214 1Stocks&bonds2214 1
Stocks&bonds2214 1dannygriff1
 
Learn VB.NET at ASIT
Learn VB.NET at ASITLearn VB.NET at ASIT
Learn VB.NET at ASITASIT
 
Is2215 lecture7 lecturer_ado_intro
Is2215 lecture7 lecturer_ado_introIs2215 lecture7 lecturer_ado_intro
Is2215 lecture7 lecturer_ado_introdannygriff1
 
Profitability&npv
Profitability&npvProfitability&npv
Profitability&npvdannygriff1
 

Andere mochten auch (8)

Is2215 lecture8 relational_databases
Is2215 lecture8 relational_databasesIs2215 lecture8 relational_databases
Is2215 lecture8 relational_databases
 
Is2215 lecture5 lecturer_g_cand_classlibraries
Is2215 lecture5 lecturer_g_cand_classlibrariesIs2215 lecture5 lecturer_g_cand_classlibraries
Is2215 lecture5 lecturer_g_cand_classlibraries
 
Is2215 lecture6 lecturer_file_access
Is2215 lecture6 lecturer_file_accessIs2215 lecture6 lecturer_file_access
Is2215 lecture6 lecturer_file_access
 
Stocks&bonds2214 1
Stocks&bonds2214 1Stocks&bonds2214 1
Stocks&bonds2214 1
 
Mcq sample
Mcq sampleMcq sample
Mcq sample
 
Learn VB.NET at ASIT
Learn VB.NET at ASITLearn VB.NET at ASIT
Learn VB.NET at ASIT
 
Is2215 lecture7 lecturer_ado_intro
Is2215 lecture7 lecturer_ado_introIs2215 lecture7 lecturer_ado_intro
Is2215 lecture7 lecturer_ado_intro
 
Profitability&npv
Profitability&npvProfitability&npv
Profitability&npv
 

Ähnlich wie Creating OOP Classes in Code

Ap Power Point Chpt4
Ap Power Point Chpt4Ap Power Point Chpt4
Ap Power Point Chpt4dplunkett
 
(An Extended) Beginners Guide to Object Orientation in PHP
(An Extended) Beginners Guide to Object Orientation in PHP(An Extended) Beginners Guide to Object Orientation in PHP
(An Extended) Beginners Guide to Object Orientation in PHPRick Ogden
 
Object Oriended Programming with Java
Object Oriended Programming with JavaObject Oriended Programming with Java
Object Oriended Programming with JavaJakir Hossain
 
BIS08 Application Development - II
BIS08 Application Development - IIBIS08 Application Development - II
BIS08 Application Development - IIPrithwis Mukerjee
 
Java 102 intro to object-oriented programming in java
Java 102   intro to object-oriented programming in javaJava 102   intro to object-oriented programming in java
Java 102 intro to object-oriented programming in javaagorolabs
 
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 2Mukul kumar Neal
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slotsmha4
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slotsmha4
 
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 scopePrem Kumar Badri
 
Object-oriented programming 3.pptx
Object-oriented programming 3.pptxObject-oriented programming 3.pptx
Object-oriented programming 3.pptxAdikhan27
 
C#.net, C Sharp.Net Online Training Course Content
C#.net, C Sharp.Net Online Training Course ContentC#.net, C Sharp.Net Online Training Course Content
C#.net, C Sharp.Net Online Training Course ContentSVRTechnologies
 
Is2215 lecture3 student (1)
Is2215 lecture3 student (1)Is2215 lecture3 student (1)
Is2215 lecture3 student (1)dannygriff1
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingAhmed Swilam
 

Ähnlich wie Creating OOP Classes in Code (20)

Ap Power Point Chpt4
Ap Power Point Chpt4Ap Power Point Chpt4
Ap Power Point Chpt4
 
Chapter 12
Chapter 12Chapter 12
Chapter 12
 
Classes2
Classes2Classes2
Classes2
 
(An Extended) Beginners Guide to Object Orientation in PHP
(An Extended) Beginners Guide to Object Orientation in PHP(An Extended) Beginners Guide to Object Orientation in PHP
(An Extended) Beginners Guide to Object Orientation in PHP
 
Object Oriended Programming with Java
Object Oriended Programming with JavaObject Oriended Programming with Java
Object Oriended Programming with Java
 
BIS08 Application Development - II
BIS08 Application Development - IIBIS08 Application Development - II
BIS08 Application Development - II
 
Java 102 intro to object-oriented programming in java
Java 102   intro to object-oriented programming in javaJava 102   intro to object-oriented programming in java
Java 102 intro to object-oriented programming in java
 
Java Reflection Concept and Working
Java Reflection Concept and WorkingJava Reflection Concept and Working
Java Reflection Concept and Working
 
Java Basics
Java BasicsJava Basics
Java Basics
 
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
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
 
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
 
Object-oriented programming 3.pptx
Object-oriented programming 3.pptxObject-oriented programming 3.pptx
Object-oriented programming 3.pptx
 
Introduction to Design Patterns
Introduction to Design PatternsIntroduction to Design Patterns
Introduction to Design Patterns
 
java tutorial 3
 java tutorial 3 java tutorial 3
java tutorial 3
 
C#.net, C Sharp.Net Online Training Course Content
C#.net, C Sharp.Net Online Training Course ContentC#.net, C Sharp.Net Online Training Course Content
C#.net, C Sharp.Net Online Training Course Content
 
Lesson 13 object and class
Lesson 13 object and classLesson 13 object and class
Lesson 13 object and class
 
Is2215 lecture3 student (1)
Is2215 lecture3 student (1)Is2215 lecture3 student (1)
Is2215 lecture3 student (1)
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
 

Mehr von dannygriff1

Ec2204 tutorial 8(2)
Ec2204 tutorial 8(2)Ec2204 tutorial 8(2)
Ec2204 tutorial 8(2)dannygriff1
 
Ec2204 tutorial 4(1)
Ec2204 tutorial 4(1)Ec2204 tutorial 4(1)
Ec2204 tutorial 4(1)dannygriff1
 
Ec2204 tutorial 3(1)
Ec2204 tutorial 3(1)Ec2204 tutorial 3(1)
Ec2204 tutorial 3(1)dannygriff1
 
Ec2204 tutorial 2(2)
Ec2204 tutorial 2(2)Ec2204 tutorial 2(2)
Ec2204 tutorial 2(2)dannygriff1
 
Ec2204 tutorial 1(2)
Ec2204 tutorial 1(2)Ec2204 tutorial 1(2)
Ec2204 tutorial 1(2)dannygriff1
 
6 price and output determination- monopoly
6 price and output determination- monopoly6 price and output determination- monopoly
6 price and output determination- monopolydannygriff1
 
5 industry structure and competition analysis
5  industry structure and competition analysis5  industry structure and competition analysis
5 industry structure and competition analysisdannygriff1
 
4 production and cost
4  production and cost4  production and cost
4 production and costdannygriff1
 
3 consumer choice
3 consumer choice3 consumer choice
3 consumer choicedannygriff1
 
2 demand-supply and elasticity
2  demand-supply and elasticity2  demand-supply and elasticity
2 demand-supply and elasticitydannygriff1
 
1 goals of the firm
1  goals of the firm1  goals of the firm
1 goals of the firmdannygriff1
 
Ec2204 tutorial 6(1)
Ec2204 tutorial 6(1)Ec2204 tutorial 6(1)
Ec2204 tutorial 6(1)dannygriff1
 

Mehr von dannygriff1 (17)

Risk08a
Risk08aRisk08a
Risk08a
 
Npvrisk
NpvriskNpvrisk
Npvrisk
 
Npv2214(1)
Npv2214(1)Npv2214(1)
Npv2214(1)
 
Irr(1)
Irr(1)Irr(1)
Irr(1)
 
Npv rule
Npv ruleNpv rule
Npv rule
 
Ec2204 tutorial 8(2)
Ec2204 tutorial 8(2)Ec2204 tutorial 8(2)
Ec2204 tutorial 8(2)
 
Ec2204 tutorial 4(1)
Ec2204 tutorial 4(1)Ec2204 tutorial 4(1)
Ec2204 tutorial 4(1)
 
Ec2204 tutorial 3(1)
Ec2204 tutorial 3(1)Ec2204 tutorial 3(1)
Ec2204 tutorial 3(1)
 
Ec2204 tutorial 2(2)
Ec2204 tutorial 2(2)Ec2204 tutorial 2(2)
Ec2204 tutorial 2(2)
 
Ec2204 tutorial 1(2)
Ec2204 tutorial 1(2)Ec2204 tutorial 1(2)
Ec2204 tutorial 1(2)
 
6 price and output determination- monopoly
6 price and output determination- monopoly6 price and output determination- monopoly
6 price and output determination- monopoly
 
5 industry structure and competition analysis
5  industry structure and competition analysis5  industry structure and competition analysis
5 industry structure and competition analysis
 
4 production and cost
4  production and cost4  production and cost
4 production and cost
 
3 consumer choice
3 consumer choice3 consumer choice
3 consumer choice
 
2 demand-supply and elasticity
2  demand-supply and elasticity2  demand-supply and elasticity
2 demand-supply and elasticity
 
1 goals of the firm
1  goals of the firm1  goals of the firm
1 goals of the firm
 
Ec2204 tutorial 6(1)
Ec2204 tutorial 6(1)Ec2204 tutorial 6(1)
Ec2204 tutorial 6(1)
 

Creating OOP Classes in Code

Hinweis der Redaktion

  1. The deposit sub procedure accepts a string value (from our text box) and converts it to a Decimal using the Decimal parse methodThis amount is then added to the balance
  2. In this example we are getting an amount from the textbox and subtracting it from our balance figureWe could have used the decimal parse method here.If we do not provide a numeric value, we will get a .NET exception error (Unexpected Data Type)
  3. See: http://visualbasic.about.com/od/learnvbnet/a/sharedinstance.htm
  4. The SavingsAccount class annotates the Balance method with the Shadows keyword to indicate the Balance method redeclares and hides the Balance property in the base class