Implementation Inheritance

Implementation inheritance or code reuse, as it is often called, is a very useful feature and time saver. However it is not so essential in providing the system your users want. Also code reuse can be achieved by 'aggregating' or 'composing' the object that contains the services (methods) you want to reuse instead.


AddCustome GetCustome


1 1


Add Item Remove

Code reuse via Inheritance

Code reuse via composition (the VB way)

In this situation, any operations you want to reuse, involves writing delegation code to delegate to the reused object. Here is an example 'customers' collection:

'this is my hidden implementation of the collection Private m_myCollection As New Collection

Public Sub AddCustomer(ByVal theCustomer As Customers) 'delegate to my collection m_myCollection.Add theCustomer End Sub

Public Sub RemoveCustomer(ByVal theCustomer As Customers) 'delegate to my collection m_myCollection.Remove theCustomer End Sub

Of course this can be very tedious when there are many services involved. This is where CASE tools are useful for doing the 'grunge work'. VB Developers may wish to develop their own VB 'add-in' that performs this task.

So to recap, if you are turning an <<extends>> inheritance relationship into containment, do the following:







If the stereotype is <<implements>> then this maps simply to the VB construct 'implements':

The VB code for the above model could look like this: -

'Employee Class

Implements CompanyAsset Implements PersistentObject

'my implementation of GetValue

Private Property Get CompanyAsset_GetValue() As Variant

'return asset value of this employee End Property

'my implementation of load Private Sub PersistentObject_Load()

'load employee details from disk End Sub

Private Sub PersistentObject_Save() 'save employee details to disk End Sub

Was this article helpful?

0 0
365 Days Of Motivation

365 Days Of Motivation

Stop Wasting Time And Learn How To Stay Motivated. Finally! Discover How To Stop Your Mind From Wandering, And Upgrade Your Motivation. You Can Hack Your Motivation Levels, Allowing You To Take Your Life To The Next Level.

Get My Free Ebook

Post a comment