Presentation is loading. Please wait.

Presentation is loading. Please wait.

8 – Objects as building blocks Visual Basic: An Object Oriented Approach.

Similar presentations


Presentation on theme: "8 – Objects as building blocks Visual Basic: An Object Oriented Approach."— Presentation transcript:

1 8 – Objects as building blocks Visual Basic: An Object Oriented Approach

2 Structures in programs Ways of grouping objects using available mechanisms Arrays, Collections Lists Simple lists of objects Stacks (Last-in, First out) Queues (Last-in, Last-out) Trees Hierarchical structures of objects Graphs Arbitrarily interconnected objects

3 Arrays Private Accounts (1..100) As AccountObj For I = 1 To 100 Set Accounts(I) = AccountObj Accounts(I).Initialise Next

4 Logical and Physical Structure Interconnect objects using references Forms of interconnection involve Logical structure The model of interconnections we wish to create Physical structure The actual mechanisms we use to create them

5 Collection Classes Specialised forms of collection Based on standard collection class Add Remove Item( ) Count Support for For Each … syntax Allows natural form of iteration over a collection

6 Queues and Stacks Collections with limitations on insertions/retrievals

7 Alternatives to Collections Tree Structures Each item can contain references to several other items Efficient for storage and retrieval Recursive

8 Objects and Links Object called DataNodeObj Private Link As DataNodeObj Private Data As … Public sub AddData(…) … Public sub Initialise Set Link = DataNodeObj If... Link.Initialise Link.AddData

9 Graphs Arbitrary interconnections Complex, and can be inefficient to code Require use of specialist algorithms to search and traverse

10 Visual Basic Structures End

11 OOP Structural Forms In general, object orientation supports Inheritance (interface only in VB) Composition (whole-part structures) Aggregation (objects with collections) Messages (interacting objects) Building an efficient, well-organised object oriented program should involve all of these to some degree

12 Structures in the real world All around us, things are organised into structures Buildings Traffic and communications networks Living organisms Complex systems built up of repeated of simple building blocks Should try to mimic this in programs

13 Modelling in VB Tendency to favour Collections in VB code Simple Efficient Direct Can be used to create a variety of logical structures The ‘Microsoft way’ Not always the best mechanism Can build custom forms of structures using references

14 Building Collection Classes Awkward to hand-code in VB Need to set properties for specialist methods of collection and collected classes Special members Item property – Default property Iterator (For…Each enumerator) VB’s class builder Generates whole collection class automatically Links collection class to collected class None of the subtle syntax errors possible in hand coding

15 Using a custom collection class Simplifies coding for client applications Add items using a simple call Iterate over collection easily Set T = New colTransactions T.Add “10/10/2000”, , “Deposit” T.Add….. ‘‘‘ For Each Tr In T T.PrintStatementLine Next

16 Alternative Collections Ordered Collection Items added in a specific order Can use binary search to insert and retrieve items Efficiency in searching (and therefore retrieval


Download ppt "8 – Objects as building blocks Visual Basic: An Object Oriented Approach."

Similar presentations


Ads by Google