21/08/2008

More words of wisdom from The Joy of Smalltalk

I found the following points to be really useful:

We will now evaluate the desirability of the selected nouns as classes:
  • Address. If the address included the name of the city, postal code, province or state, and other information, we would implement it as a class. As it is, an address is just a string of alphabetic and numeric characters and strings are already in the library. We thus remove Address from our list of candidates.

  • Apartment. Yes, we will implement this concept as a new class because it represents an object that holds a lot of apartment information together and no related class exists in the library. The class will be called Apartment and we will decide shortly what exact meaning it will have.

  • Building. Another and non-trivial object that does not have a counterpart in the library and will have to be implemented. The class will be called Building.

  • File. The concept of a file is implemented in VisualWorks library and does not require a new class.

The reason I found this so helpful is that it provides some really useful heuristics for object modelling. If what you are trying to store exists as a simple object, e.g. a string for address, then don't bother creating a new class. If, on the other hand, it is a more complex 'type', AND, you can't find an existing object that will do. Create a new one.

Blindingly obvious and really helpful

No comments: