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

Info icon This preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Murach’s Visual Basic 2008, C17 © 2008, Mike Murach & Associates, Inc. Slide 1 Chapter 17 How to work with default properties, events, and operators
Image of page 1

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

View Full Document Right Arrow Icon
Murach’s Visual Basic 2008, C17 © 2008, Mike Murach & Associates, Inc. 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.
Image of page 2
Murach’s Visual Basic 2008, C17 © 2008, Mike Murach & Associates, Inc. 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
Image of page 3

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

View Full Document Right Arrow Icon
Murach’s Visual Basic 2008, C17 © 2008, Mike Murach & Associates, Inc. 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
Image of page 4
Murach’s Visual Basic 2008, C17 © 2008, Mike Murach & Associates, Inc. Slide 5 The code for a simple ProductList class (cont.) Public Sub Save() ProductDB.SaveProducts(products) End Sub End Class
Image of page 5

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

View Full Document Right Arrow Icon
Murach’s Visual Basic 2008, C17 © 2008, Mike Murach & Associates, Inc. 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.
Image of page 6
Murach’s Visual Basic 2008, C17 © 2008, Mike Murach & Associates, Inc. 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() Fills the list with product data from a file. Save() Saves the products to a file.
Image of page 7

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

View Full Document Right Arrow Icon
Murach’s Visual Basic 2008, C17 © 2008, Mike Murach & Associates, Inc. Slide 8 A default property that uses an integer as a parameter Private products As List(Of Product) Default Public Property Item(ByVal index As Integer) _ As Product Get Return products(index) End Get Set(ByVal value As Product) products(index) = value End Set End Property
Image of page 8
Murach’s Visual Basic 2008, C17 © 2008, Mike Murach & Associates, Inc.
Image of page 9

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

View Full Document Right Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern