Presentation is loading. Please wait.

Presentation is loading. Please wait.

IS437: Fall 2004 Instructor: Dr. Boris Jukic

Similar presentations


Presentation on theme: "IS437: Fall 2004 Instructor: Dr. Boris Jukic"— Presentation transcript:

1 IS437: Fall 2004 Instructor: Dr. Boris Jukic
Building Business Objects: Part 2

2 Inheritance Creating a new class, based on existing class
All non-private members (elements) are inherited in the new , derived class In addition, all methods can be inherited (public or private) Public Class StudentBookSale Inherits BookSale

3 Inheritance: Constructor
Sub New(ByVal Title As String, ByVal Quantity As Integer, ByVal Price As Decimal) MyBase.New(Title, Quantity, Price) CalculateStudentTotals() End Sub Base class constructor A new method, specific to the subclass only Derived subclass does not explicitly inherit the parent’s class constructor method It needs its own, within it can call the base class constructor Additional methods can be specified in the constructor class of the derived class

4 Inheritance: Polymorphism through Overriding Methods
Protected Overrides Sub CalculateItemPrices() End Sub Method as defined in derived class Protected Overridable Sub CalculateItemPrices() End Sub Method as defined in base class Derived subclass can implement a method from the base (parent) class in a different way The method as described in the derived class overrides the method as defined in the base class when an instance of the inherited class is instantiated and used

5 Inheritance: Overriding Methods
Protected Overrides Sub CalculateItemPrices() ExtendedPrice = Quantity * Price Discount = ExtendedPrice * STUDENT_DISCOUNT_RATE DiscountedPrice = ExtendedPrice - Discount End Sub Base class properties are used in calculations, but not base class private variables The method as defined in the derived (child) class can access the values of the properties defined in the base class The methods in children class do not have access to the private variables of the parent class

6 Inheritance: New Methods and Properties in Derived Class
Private Shared decimalTotalStudentDiscount As Decimal Property TotalStudentDiscount() As Decimal Get Return decimalTotalStudentDiscount End Get Set(ByVal Value As Decimal) decimalTotalStudentDiscount = Value End Set End Property Private Sub CalculateStudentTotals() decimalTotalStudentDiscount += Discount End Sub Derived classes can have their own original (non-inherited methods and properties The values of those original properties are contained in the private variables defined in the inherited class module


Download ppt "IS437: Fall 2004 Instructor: Dr. Boris Jukic"

Similar presentations


Ads by Google