29.11.2014 Views

Smalltalk and Object Orientation: an Introduction - Free

Smalltalk and Object Orientation: an Introduction - Free

Smalltalk and Object Orientation: an Introduction - Free

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

19.3.2.4 Identify attributes of objects<br />

OMT suggests that attributes correspond to nouns followed by possessive phrases, such as “the color of<br />

the car” or “the position of the cursor” in the problem statement. Although the authors do admit that<br />

attributes are less likely to be fully described in the probl em statement <strong><strong>an</strong>d</strong> that you must draw on your<br />

knowledge of the application domain <strong><strong>an</strong>d</strong> the real world to find them. If you have already used a method<br />

such as OOA you may already have identified the key attributes. Luckily attributes c<strong>an</strong> (usually) be<br />

easily added to objects as <strong><strong>an</strong>d</strong> when they are identified - it is rare that the addition of a new attribute will<br />

cause the structure of the system to become unstable.<br />

An import<strong>an</strong>t point to note is that you should only be trying to identify application domain attributes.<br />

This me<strong>an</strong>s that attributes which will be needed during the implementation of the system should not be<br />

included at this stage. However, link attributes (which might appear to be implementation attributes)<br />

should be identified at this stage as they have <strong>an</strong> impact on the systems structure. A link attribute is a<br />

property of the link between two objects, rather th<strong>an</strong> being a property of <strong>an</strong> individual object. For<br />

example, the m<strong>an</strong>y to m<strong>an</strong>y association between Stockholder <strong><strong>an</strong>d</strong> Comp<strong>an</strong>y has a link attribute of<br />

“number of shares”.<br />

Having identified the set of c<strong><strong>an</strong>d</strong>idate attributes for each object you should then challenge these<br />

attributes using the following criteria:<br />

Should the attribute be <strong>an</strong> object? For example, earlier we said that a telephone call should not be <strong>an</strong><br />

object, however if you are constructing a telephone call billing system, then it is probable that it should<br />

be <strong>an</strong> object. You therefore need to think carefully about the domain when deciding whether something<br />

is <strong>an</strong> attribute or <strong>an</strong> object. Don’t worry ab out getting it wrong (there may be no correct <strong>an</strong>swer) you<br />

c<strong>an</strong> come back to it later <strong><strong>an</strong>d</strong> refine the model.<br />

Is <strong>an</strong> attribute really a name ? Names are often actually selectors used to identify a unique object<br />

from a set of objects. In such situations a name should really be a qualifier.<br />

Is <strong>an</strong> attribute <strong>an</strong> identifier ? Here identifier relates to a computer based identifier <strong><strong>an</strong>d</strong> is <strong>an</strong><br />

implementation issue <strong><strong>an</strong>d</strong> not part of the application domain. For example, objectId is <strong>an</strong> identifier<br />

which is probably not in the applications domain.<br />

Is <strong>an</strong> attribute really a link attribute ? Link attributes are often mistaken for object attributes. Link<br />

attributes are most easily identified when it becomes difficult to identify which of two (or more) classes<br />

the attribute should belong to. In such situations it is <strong>an</strong> attribute of the link between the two classes.<br />

Does the attribute represent <strong>an</strong> internal state of the object which is not visible outside the object ? If<br />

it does remove the attribute. It is <strong>an</strong> internal implementation issue <strong><strong>an</strong>d</strong> not part of the domain problem.<br />

Does the attribute represent fine detail? If the attribute represents some aspect of the object which is<br />

relatively low level then omit it. It will not help with the overall underst<strong><strong>an</strong>d</strong>ing of the domain <strong><strong>an</strong>d</strong> will<br />

increase the complexity of the object model.<br />

Are <strong>an</strong>y of the attributes unlike the others in their class ? Such discord<strong>an</strong>t attributes may either be<br />

misplaced (this may indicate that one class should actually be two or more) or that the attribute is not<br />

part of the current application (although it may be part of the overall domain).<br />

19.3.2.5 Org<strong>an</strong>ize <strong><strong>an</strong>d</strong> simplify object classes using inherit<strong>an</strong>ce<br />

The next step is to refine your classes using inherit<strong>an</strong>ce. This c<strong>an</strong> be done in both directions, that is,<br />

either by grouping common aspects of existing classes into a superclass from which the existing classes<br />

inherit or by specializing <strong>an</strong> existing class into a number of more specialized subclasses which serve<br />

specific purposes. Again if you have used <strong>an</strong> <strong>an</strong>alysis method such as OOA, some o f this may already<br />

have been performed. Note that you are not doing this with a view to implementing the class hierarchy<br />

being generated, rather you are trying to underst<strong><strong>an</strong>d</strong> the commonalities in the domain.<br />

Identifying potential superclasses is easier tha n identifying specialized subclasses. To find potential<br />

superclasses, you should examine the existing classes looking for common attributes, operations or<br />

associations. Any common patterns you find may indicate the potential for a superclass. If such a<br />

situation is found, then the superclass should be defined with <strong>an</strong> appropriate name (i.e. one that<br />

encompasses the generic roles of the class which will inherit from it). Then move the attributes,<br />

associations <strong><strong>an</strong>d</strong> operations which are common up into this super class. Do not try to force unrelated<br />

classes to become subclasses of a superclass just because they happen to have similar attributes (or<br />

associations or operations). Attempt to make sure that when you do group a set of classes together under<br />

a superclass, that grouping makes sense in the application domain. For example, grouping the classes<br />

160

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!