13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

12.5 Finding the Methods and Attributes283remaining cards, we can quickly see that we have two cards that are accounts:“Capital Account” and “Current Account.” These are both pools of m<strong>on</strong>ey.Put them <strong>on</strong> top of <strong>on</strong>e another <strong>on</strong> the table. Likewise, it is fairly obvious that“CEO,” “CFO,” “Director,” and “Manager” are all people. Put them together<strong>on</strong> the table.Remember that we are looking for simplifying abstracti<strong>on</strong>s. The groupedcards should all be obviously variant types of a generic class of objects. In ourexample, the <strong>on</strong>e is a stack of Accounts, and the other is a stack of People, or,as we will call them, Users. Create new cards for these generic classes. Make acard with “Account” at the top and put it above the first stack. Make anothercard with “User” at the top and put it above the sec<strong>on</strong>d stack.There are two ways that this might simplify your design. For now, all cardsbelow the abstract cards are “<strong>on</strong> probati<strong>on</strong>.” We are going to move <strong>on</strong> to definethe attributes (data) and methods (behavior) of our abstract classes. If the abstractclass can handle all use cases without having to treat any of the morespecific classes differently, then the specific cards are discarded. If not, then allfuncti<strong>on</strong>ality that is comm<strong>on</strong> across the more specific types will be put <strong>on</strong> theabstract class card, and <strong>on</strong>ly those data and behaviors that are different will beput <strong>on</strong> the more detailed cards.In the first case, the simplificati<strong>on</strong> is a reducti<strong>on</strong> of several potential classesto a single class. This is always a good thing, when it is possible. In the sec<strong>on</strong>dcase, you are identifying potential inheritance relati<strong>on</strong>ships. 412.5FINDING THE METHODS AND ATTRIBUTESThe next step is to start identifying the data and behavior that characterize yourclasses. Always put such items <strong>on</strong> the most abstract class first. The <strong>on</strong>ly time toadd an attribute or method to a more specific class is when it applies to thatclass and <strong>on</strong>ly that class—in other words, <strong>on</strong>ly when it represents a differencebetween the general case and the specific case. 54. We’ll talk more about that later in the book. As it happens, all of our simplificati<strong>on</strong>s in thischapter are examples of the first case.5. In complex cases, you may find an attribute or method that applies to several, but not all,of the specific cases. In such a case, a new abstract class below the main abstract class, but aboveall the specific classes that share that attribute or method, may be called for.

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

Saved successfully!

Ooh no, something went wrong!