The document discusses object-oriented programming concepts like classes, properties, methods, constructors, inheritance, polymorphism, and more by providing examples of how to code an ATM application and bank account class. It shows how to create classes in code by adding a class, providing a name, declaring properties and methods, and adding constructors/destructors. Derived classes can inherit and override base class members. Polymorphism allows using derived class instances interchangeably with the base class.
3. 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
5. 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
6. 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
8. 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
11. 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
14. 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
16. 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
20. 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
29. 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
33. 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
35. 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
57. 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
60. 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
61. 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
70. Shadowing
To indicate a derived class member shadows
a base class member
Use the Shadows Keyword
71. 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
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
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)
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