Your SlideShare is downloading. ×
0
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Is2215 lecture4 student (1)
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Is2215 lecture4 student (1)

255

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
255
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • 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)
  • See: http://visualbasic.about.com/od/learnvbnet/a/sharedinstance.htm
  • 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
  • Transcript

    • 1. DOING IT IN CODESOME MORE EXAMPLES
    • 2. EXAMPLE 1ATM
    • 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
    • 4. Example #1
    • 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
    • 7. 1. Add Class to the Project
    • 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
    • 9. 2. Provide Appropriate Name
    • 10. 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. 3. Declare Properties
    • 12. 3. Declare Properties
    • 13. 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. 4. Property Procedures This property is ReadOnly
    • 15. 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. 3. Create Methods
    • 17. 5. Deposit
    • 18. 5. Withdraw
    • 19. 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. EXAMPLE 2BANK ACCOUNT
    • 21. Declare propertiesProperty ProceduresCreate MethodsAdd constructors/destructors if needed
    • 22. 1.Declare Properties
    • 23. Declare propertiesProperty ProceduresCreate MethodsAdd constructors/destructors if needed
    • 24. 2. _name Retrieve Value Store Value
    • 25. 2. _balance
    • 26. 2. _MaximumWithdrawal
    • 27. 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
    • 28. 2. Shared _Rate
    • 29. Declare propertiesProperty ProceduresCreate MethodsAdd constructors/destructors if needed
    • 30. Deposit()
    • 31. 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
    • 32. Deposit ()
    • 33. 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
    • 34. Withdraw ()
    • 35. CalculateInterest()
    • 36. IncreaseRate ()
    • 37. Declare propertiesProperty ProceduresCreate MethodsAdd constructors/destructors if needed
    • 38. 4. Overloading Constructors
    • 39. In UseDim account as New _ BankAccount()
    • 40. Overloading Constructors
    • 41. In UseDim account as New _ BankAccount(“Joe”)
    • 42. Overloading Constructors
    • 43. In UseDim account as New _ BankAccount(“Joe”, 1000)
    • 44. 4. Overriding Destructor
    • 45. Using the ClassInstantiating the Object
    • 46. Create Object
    • 47. Withdrawing Cash
    • 48. Method InputBox
    • 49. Withdrawing Cash
    • 50. Method
    • 51. Depositing Cash
    • 52. Calculate Interest
    • 53. Method Val(txtRate.Text) / 100).ToString( "C"))
    • 54. Extending our ExampleAdvanced OOP
    • 55. Accessibility LevelsAccess Level Visual Basic Access ModifierUnrestricted accessibility PublicAccessible by containing PrivateclassAccessible in current FriendassemblyAccessible by containing Protectedclass and derived classAccessible in current Protected Friendassembly and by derivedclasses
    • 56. Inheritance Advantages  Developer Productivity  Real-world modelling  Consistency
    • 57. Base classDerived Classes
    • 58. 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
    • 59. Polymorphism enables an application to use instances ofderived classes interchangeably Deposit A SavingsAccount Client application Deposit A CheckingAccountBenefits of polymorphism: Consistency and simplicity Extensibility and resilience
    • 60. Base Class Properties
    • 61. Base Class Properties
    • 62. Base Class Properties
    • 63. Base Class Methods
    • 64. Base Class Methods
    • 65. Derived Class
    • 66. Derived Class
    • 67. Derived Class
    • 68. Shadowing To indicate a derived class member shadows a base class member  Use the Shadows Keyword
    • 69. ExamplePublic Class BankAccount Protected ReadOnly Property _ Balance() As Decimal End PropertyPublic Class SavingsAccountPublic Shadows Sub Balance( _ ByVal amount As Decimal) „ImplementationEnd Sub
    • 70. Combining and Overloading
    • 71. Combining and Overloading
    • 72. Implement the Class

    ×