Chapter 17 slides - Chapter 17 How to work with default...

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

View Full Document Right Arrow Icon
Murach’s Visual Basic 2008, C17 Slide 1 Chapter 17 How to work with default properties, events, and operators
Background image of page 1

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

View Full DocumentRight Arrow Icon
Murach’s Visual Basic 2008, C17 Slide 2 Objectives Applied Develop and use classes that have default properties, events, and overloaded operators. Knowledge Describe the use of a default property. Explain why you should validate parameters and throw exceptions in your classes. Describe the use of events. Describe the use of operator overloading.
Background image of page 2
Murach’s Visual Basic 2008, C17 Slide 3 The code for a simple ProductList class Public Class ProductList Private products As List(Of Product) Public Sub New() products = New List(Of Product) End Sub Public ReadOnly Property Count() As Integer Get Return products.Count End Get End Property Public Sub Add(ByVal product As Product) products.Add(product) End Sub
Background image of page 3

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

View Full DocumentRight Arrow Icon
Murach’s Visual Basic 2008, C17 Slide 4 The code for a simple ProductList class (cont.) Public Sub Add(ByVal code As String, _ ByVal description As String, _ ByVal price As Decimal) Dim p As New Product(code, description, price) products.Add(p) End Sub Public Sub Remove(ByVal product As Product) products.Remove(product) End Sub Public Function GetProductByIndex(ByVal i As Integer) _ As Product Return products(i) End Function Public Sub Fill() products = ProductDB.GetProducts End Sub
Background image of page 4
Murach’s Visual Basic 2008, C17 Slide 5 The code for a simple ProductList class (cont.) Public Sub Save() ProductDB.SaveProducts(products) End Sub End Class
Background image of page 5

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

View Full DocumentRight Arrow Icon
Murach’s Visual Basic 2008, C17 Slide 6 The members of the ProductList class Property Description Count An integer that indicates how many Product objects are in the list. Item( index ) A default property that provides access to the product at the specified position. Item( code ) A default property that provides access to the product with the specified code. Operator Description + Adds a Product object to the list. - Removes a Product object from the list. Event Description Changed Raised whenever a Product object is added to or removed from the list.
Background image of page 6
Slide 7 The members of the ProductList class (cont.) Method Description Add( product ) Adds the specified Product object to the list. Add( code, description, price ) Creates a Product object with the specified code, description, and price values, and then adds the Product object to the list. Remove( product ) Removes the specified Product object from the list. Fill()
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/14/2010 for the course BS computer p taught by Professor Smith during the Spring '10 term at Virtual University of Pakistan.

Page1 / 29

Chapter 17 slides - Chapter 17 How to work with default...

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

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