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 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

3 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

4 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

5 Choice of Structure Various selection criteria Organisational form of system we are modelling Storage efficiency – space required to store items Computational efficiency – how long to add and remove objects Often a trade-off is necessary

6 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 i

7 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

8 Collection Classes Specialised forms of collection Based on standard collection class, but.. Optimised for storing and retrieving a specific class of object Implement standard class interface… Add Remove Item( ) Count Support for For..Each syntax Allows natural form of iteration over a collection

9 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

10 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”, 150.00, “Deposit” T.Add….. ‘‘‘ For Each Tr In T T.PrintStatementLine Next

11 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

12 Queues and Stacks Collections with limitations on insertions/retrievals

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

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


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

Similar presentations


Ads by Google