Design Patterns in VB.NET - Terms to Know
page 3 of 4
by David Simmonds
Feedback
Average Rating: 
Views (Total / Last 10 Days): 22337/ 76

Terms used in the GoF Book

Interface Inheritance versus Implementation Inheritance

In the first case, we are referring to a class inheriting from an interface (or in VB terms, implementing the interface).  In the second case, we mean a class inheriting from a super-class.

 

Classes having knowledge of other classes

When one class knows about another class, it simply means that it holds a reference to the other class and its methods and properties.

Let us look at it from another angle.  When coding a class which knows another class, you have to know exactly which class it will need to use, the name of the class, etc.  You may also need to know its internal workings.  Obviously, it translates into higher coupling since a change to the referred class can mean a change the referee class.

 

Wide Interfaces

When a class interacts with, accesses and/or modifies another class through a wide interface, it means that it has intimacy with that other class.  It means that the "interactor" has wide knowledge of the "interactee" and is able to get its work done through that wide knowledge.  A wide interface means that the class knows all the methods and member variables which are available in order to manipulate them intimately.  We see this type of interaction between director and concrete-builder in the Builder-pattern.

Obviously, this not only breaks encapsulation, but it also greatly increases coupling.  It is somewhat similar to the wife who knows every little detail about the husband and how he thinks.  She knows just the right words to say and the little looks to drop to get him to do something.  She is interacting through a wide interface since she can reach across a wide set of psychological handles that affect his behaviour and the action she desires.  She knows the exact way to angle her face, remove a lock of hair and crease her lips to stimulate just the right part of the man’s psyche into action.  I do not say this is a bad thing; in fact, it is very necessary.  Men are lazy and need pushing and prodding.  It is simply an example of a wide interface.

Interaction through a wide interface makes for stability in marriage since a wife and husband are the hardest people to replace, their interactions being so complex, multi-faceted and fine-tuned. In the average circumstances, it gives children a stable environment in which to grow up and enjoy the input of both parties in their development.  So in fact, society benefits from the fact that wives interact with their husbands through wide interfaces.

 

Narrow Interfaces

A narrow interface is the interface through which most classes would normally interact with another class.  It normally consists of the interaction with properties and methods in a way that assumes a minimum of knowledge about the class, possibly just a single method name to invoke.

 

Aggregation versus acquaintance

Do not fall into the trap that I did when I confused aggregation with the use of a data-structure which contains several references to the aggregatee.  Aggregation has nothing to do with numbers and may involve one aggregatee or many.  So it may in fact be through a data-structure, but more times than not through a single object reference.

So what is it?  Aggregation means that the aggregator and aggregatee are bound in such a way that the useful object lifetime of the aggregatee is also the useful lifetime of the aggregator.  For as long as the aggregator has useful work to do, it needs the aggregatee to do so.

So think object lifetime and not numbers.  Due to the link between their useful lifetimes, it becomes useful for the aggregator’s constructor method to include the instantiation of a new aggregatee-helper class at the same time.  The destructor of the helper class is also tied to that of the main class.

For on-line browsing the web-browser needs to have a reference to a live internet connection and so the browser aggregates the internet-connection. Therefore we see the aggregator/aggregatee principle in the web browsers’ connection settings where the activation of the browser can be tied to the activation of the connection in the settings below.

Listing 1: Internet Options showing aggregator principle

 

 

Launching Internet explorer (in the absence of a network internet connection) automatically brings up the following.

 

Listing 2: Web browser instantiating a connection

 

 

 

Similarly, when there is no web browser to send useful work through the internet connection, there is no point in keeping it alive and we can configure dial-up connections to reflect this with the following dialog.  We configure the connection to be disposed of with the browser by setting the number of minutes we should allow the connection to be idle before disconnecting it.

 

Listing 3: Disposing connections when the browser shuts down

 

 

 

In the Builder pattern we can see a director as the aggregator and the concrete-builder as the aggregatee.

 

Acquaintanceship

Acquaintanceship is when there is a reference to an acquaintance class.  However, the usefulness of the main class is not tied to the usefulness of the acquaintance.  It used to be that someone’s heart dictated the number of years they could live.  If your ticker gave up, you were forced to do the same.  Thankfully, this is not so anymore. Your heart is now a helper object, not the main object.  You are the one with the relationship to your kids, spouse, co-workers, community, clubs, country and God.  Your heart is here to help you to keep on living; you are not here to live just because your heart decides to continue beating.

Medical science recognizes this and has made dramatic and far reaching progress in cardiac medicine.   We have valve replacement, bypasses, pace-makers and, in the most extreme circumstances, heart transplants.  All these techniques mean that you now have an (albeit very strong) acquaintance with your heart.  Their lifetimes are no longer inextricably linked in an aggregator/aggregatee relationship.

Acquaintance is more typical in the bridge pattern.

 

Factory-Classes

In the creational patterns, factory classes perform instantiation services (return new product classes) on behalf of client code.  They make the decision about which class should be instantiated based on the needs communicated by the client code.  This allows clients to focus on the main work they are supposed to perform without worrying about how to procure the tool-classes they need.  In the same way you do not want to go to work everyday and worry about how they supply drinking water, clean air and office supplies at your office, the factory classes free and decouple the main classes from the tedium of instantiating other classes.

 

Product-Classes

The classes which are instantiated by factory classes and returned to the client are called product-classes.  They are usually returned not as an instance of the class they are defined as, but as the interface they implement.  This ensures that they are interchangeable and, regardless of the actual product class returned, it works seamlessly with the client.

 


View Entire Article

User Comments

Title: Vb.net   
Name: Sathiya
Date: 2010-12-29 2:45:58 AM
Comment:
I want to learn vb.net basic controls with example
Title: vb.net   
Name: d.sravan
Date: 2009-09-04 3:26:06 AM
Comment:
i want to learn vb.net basic codes and commands with examples.
Title: vb.net   
Name: M.Riaz
Date: 2009-02-06 10:34:13 AM
Comment:
My Email is gccriaz@yahoo.com.
I want to learn gridview behaviour also inform me how can I pick value from a perticular cell.
Title: vb.net   
Name: john
Date: 2007-08-31 12:49:47 AM
Comment:
i neeed to learn vb.net basic codes and commands in 10 days.

MY mail id is john.earnest24@yahoo.com
kINDLY DO THE NEEDFUL.
Title: Feedback   
Name: Matt
Date: 2007-07-17 1:24:14 PM
Comment:
What is the GoF book?
Title: Feed Back   
Name: Suresh
Date: 2007-01-11 5:23:43 AM
Comment:
The article is good.I got some idea to implement design patterns

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2019 ASPAlliance.com  |  Page Processed at 2019-08-24 11:23:17 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search