chap07 - Chapter 7 Adding Responsibilities to Problem...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
Object-Oriented Application Development Using VB .NET 1 Chapter 7 Adding Responsibilities to Problem Domain Classes
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Object-Oriented Application Development Using VB .NET 2 Objectives In this chapter, you will: Write a new problem domain class definition Create custom methods Write class variables and methods Write overloaded methods Work with exceptions
Background image of page 2
Object-Oriented Application Development Using VB .NET 3 Writing a New Problem Domain Class Definition Slip class Attributes slipId slipWidth slipLength Custom method LeaseSlip
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Object-Oriented Application Development Using VB .NET 4 Writing a New Problem Domain Class Definition Class definition of Slip Class header Public Class Slip Attribute definition statements Private slipId As Integer Private slipWidth As Integer Private slipLength As Integer
Background image of page 4
Object-Oriented Application Development Using VB .NET 5 Writing a New Problem Domain Class Definition Class definition of Slip (Continued) Parameterized constructor Enables attributes to be automatically populated whenever an instance is created Public Sub New(ByVal aSlipId As Integer, _ ByVal aSlipWidth As Integer, ByVal aSlipLength As Integer) Argument data types must be assignment compatible with parameter data types
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Object-Oriented Application Development Using VB .NET 6 Writing a New Problem Domain Class Definition Class definition of Slip (Continued) Statements to populate the Slip attributes To avoid redundant code, setter methods are invoked instead of directly assigning the values 'invoke setter methods to populate attributes SetSlipId(aSlipId) SetSlipWidth(aSlipWidth) SetSlipLength(aSlipLength)
Background image of page 6
Object-Oriented Application Development Using VB .NET 7 Writing a New Problem Domain Class Definition Class definition of Slip (Continued) TellAboutSelf method Invokes the three getters Concatenates the returned values Returns the result Public Function TellAboutSelf() As String Dim info As String info = "Slip: Id = " & GetSlipId() & ", Width = " & GetSlipWidth() _ & ", Length = " & GetSlipLength() Return info End Function
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Object-Oriented Application Development Using VB .NET 8 Writing a New Problem Domain Class Definition Class definition of Slip (Continued) TellAboutSelf method Polymorphic methods Two methods with the same name, residing in different classes, that behave differently Example: TellAboutSelf methods for Customer and Slip classes Setter and getter methods
Background image of page 8
Object-Oriented Application Development Using VB .NET 9 Creating Custom Methods Custom methods Process data Accessor methods Store and retrieve attribute values LeaseSlip method A custom method Computes the lease fee for a slip Fees range from $800 to $1,500 depending on the slip’s width
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Object-Oriented Application Development Using VB .NET 10 Creating Custom Methods LeaseSlip method A Function procedure Will return a value: the lease fee amount Has Public accessibility
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 43

chap07 - Chapter 7 Adding Responsibilities to Problem...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online