Seminar 4: Wrapping upProgramming Paradigms[The Paradigms - Group 2]
2Previous Seminar
3This Seminar
Assigning ResponsibilitiesResponsibilities includes the behaviors exhibited by a class or the knowledge which a class holds.KnowledgeBehaviors
Assigning ResponsibilitiesMain TaskUse of scenarios androle play for the discovery of responsibilities.Scenario:Withdrawing cash from ATMActor CustomerReceipt Printer ClassActor ATM
Assigning Responsibilities“Focus on What the classes need to do, not how they do it.” Asking how a class behaves will result deriving false semantic distinctions which disallow the use of polymorphism.
Assigning ResponsibilitiesLet’s get it started…Responsibility Detection Guidelines
Assigning ResponsibilitiesResponsibility Detection GuidelinesBrainstorm to identify a set of candidate responsibilities for the core classes. Strive for inclusion of responsibilities  rather than exclusion
Assigning ResponsibilitiesResponsibility Detection GuidelinesThink in a more complex way will have most responsibilities listed in one of two classes.Account ClassDeposit ClassBankCardClassInsignificant to reuseInsignificant to reuseInflexible to reuseBalanceInquiry ClassWithdrawalClassInsignificant to reuseInsignificant to reuse
Assigning ResponsibilitiesResponsibility Detection GuidelinesReduce classes to “records”, which they simply know what information they hold.InteractsAim to have distinct role for each classes to encourage reuse!
Assigning ResponsibilitiesResponsibility Detection GuidelinesAbstract related classes which have common responsibilities to build hierarchies of classes.All of them execute a final transaction
Assigning ResponsibilitiesResponsibility Detection GuidelinesAbstract class make clear and cohesive responsibility assignment and take advantage ofuse polymorphism!
Assigning ResponsibilitiesResponsibility Detection GuidelinesExperiment with different configuration of classes or assignments of responsibilities.Changing the CRC cards are easier than changing the code later in the project.
Assigning CollaboratorsGuidelinesUsing Scenarios and Role PlayUsing Class HierarchyUsing DependenciesUsing Client, Servers and Contract Map
Use Scenarios and Role PlayMake a list of scenarios using the CRC core classesFill in the cards as you role play the different scenarioAssigning CollaboratorsMany practitioners uses role play and scenarios before listing the responsibilities for each classes
Using Class HierarchyHierarchy is a signal for collaborationLook up a hierarchy to class that is more abstract responsibilitiesLook down a hierarchy to carry out more specialize responsibilitiesLook for class that share same responsibilitiesAssigning Collaborators
Example19Assigning CollaboratorsTransactionsWithdrawalDepositBalanceInquiryExecuteFinancialTransaction()ExecuteFinancialTransaction()ExecuteFinancialTransaction()ExecuteFinancialTransaction()
Using DependenciesA class that depend on another for informationAssigning CollaboratorsWhen dealing with dependencies think of encapsulation
Example21Assigning CollaboratorsTransactionReceiptPrinterExecuteFinancialTransaction()printReceipt()
Using Client, Servers and Contract MapClient is a class that requires service from anotherServers are providers for the servicesAssigning CollaboratorsA Class can be a server and a client in a system
Using Client, Servers and Contract MapContracts can be used to track client server collaboration Using role play can rapidly mapped out the collaborationAssigning CollaboratorsAlternative in using client server would be identifying of message passing in the system
Example of ContractAssigning CollaboratorsContract 1: Access and Modify Account BalanceServer: AccountClient: withdrawal, Transfer, Deposit, InquiryDescription: Defines the manner in which account can be accessed or modified
Warning!!!!Collaborations can be hard to spot before role playTry to avoid class with the same responsibilities
GuidelinesLook for “Kind-of” relationshipDo not confuse “Part-of ” with “Kind-of”Name Key AbstractionsLook for Framework
Look for “Kind-of” relationshipFind classes that Share Same ResponsibilitiesShare Same BehaviorBelong Together
ExampleTransactionsWithdrawalDepositBalanceInquiry# completeTransaction()# completeTransaction()# completeTransaction()# completeTransaction()29
Do not confuse “Part-of ” with “Kind-of”Part-of DO NOT:Shared same behaviorA class maybe part of another class A and also a kind of another class B
Name Key AbstractionsName a key abstraction classidentify abstract classes that do not draw on colloquial ways of talking about system diagramA single class that have choices depending on situation
Example
Look for FrameworkThis take advantage of successful framework rather then inventing themUsing of analysis pattern to help looking for your own frameworks“Party” Pattern
34The CRC Card Technique
Thank you!End of Presentation

Programming Paradigm Seminar 4

Editor's Notes

  • #3 Discovering Candidate ClassesRead Requirements DocumentsUnderline nouns and noun phrasesAdd them to candidate class listBrainstorm to find other potential classesClarifying the ScopeSelecting Core ClassesArchitectural DesignIdentify hot spotsUse appropriate design patternsTake advantage of existing software frameworksEliminate Unnecessary ClassesRemove ghost classesCombine synonyms Distinguish attributes from classes
  • #4 Discovering Candidate ClassesRead Requirements DocumentsUnderline nouns and noun phrasesAdd them to candidate class listBrainstorm to find other potential classesClarifying the ScopeSelecting Core ClassesArchitectural DesignIdentify hot spotsUse appropriate design patternsTake advantage of existing software frameworksEliminate Unnecessary ClassesRemove ghost classesCombine synonyms Distinguish attributes from classes
  • #6 Behavior:Do things that meet the demands of the uses of the systemKnowledge: Supply information about themselves
  • #10 Strive for inclusion of relevant responsibilities rather than exclusion. Don't worry about duplication. Later refine the lists of responsibilities. Name each carefully. Given a set of core classes:Brainstorm to identify a set of candidate responsibilities for the core classes.
  • #11 Instead of having all responsibilities listed in one or two classes, which is more towards a procedural perspective. Does not take advantage of Polymorphism and encapsulation.ATM example: A tendency might be to give most of the responsibility to the Account class, which becomes a strong, busy "manager" procedure giving commands to relatively weak, ill-defined "worker" classes. Account is probably too inflexible to be directly reused; the other classes are probably too insignificant to be reused. Give each class a distinct role in the system. Strive to make each class a well-defined, complete, cohesive abstraction. Such a class has higher probability of being reused. ATM example: Give class Withdrawal the responsibility "Withdraw Funds", making it potentially useful to any other class needing to do a withdrawal. Give class Account the responsibility "Accept Withdrawal", which will, of course, be carried out by collaborating with Withdrawal. Factoring out complexity also involves identifying specialized behaviors that occurs repeatedly and, as appropriate, spinning off new classes. ATM example: The capturing and responding to user requests might be factored out into a new class Form with a responsibility "ask user for information".
  • #12 Instead of having all responsibilities listed in one or two classes, which is more towards a procedural perspective. Does not take advantage of Polymorphism and encapsulation.ATM example: A tendency might be to give most of the responsibility to the Account class, which becomes a strong, busy "manager" procedure giving commands to relatively weak, ill-defined "worker" classes. Account is probably too inflexible to be directly reused; the other classes are probably too insignificant to be reused. Give each class a distinct role in the system. Strive to make each class a well-defined, complete, cohesive abstraction. Such a class has higher probability of being reused. ATM example: Give class Withdrawal the responsibility "Withdraw Funds", making it potentially useful to any other class needing to do a withdrawal. Give class Account the responsibility "Accept Withdrawal", which will, of course, be carried out by collaborating with Withdrawal. Factoring out complexity also involves identifying specialized behaviors that occurs repeatedly and, as appropriate, spinning off new classes. ATM example: The capturing and responding to user requests might be factored out into a new class Form with a responsibility "ask user for information".
  • #13 Build hierarchies of classes. Abstract the essence of related classes by identifying where they have common responsibilities -- where they do the same thing, but do it differently -- same "what", different "how". That is, look for opportunities for the classes to use polymorphism to implement the same responsibility differently. The new parent classes may be abstract classes. That is, no actual objects may ever exist of that type. The abstract class exists to link together similar concrete types of objects. ATM example: Create an abstract class Transaction that is a superclass for Withdrawal, Deposit, etc. It can have an abstract responsibility "execute a financial transaction", that is implemented differently for each subclass
  • #14 Build hierarchies of classes. Abstract the essence of related classes by identifying where they have common responsibilities -- where they do the same thing, but do it differently -- same "what", different "how". That is, look for opportunities for the classes to use polymorphism to implement the same responsibility differently. The new parent classes may be abstract classes. That is, no actual objects may ever exist of that type. The abstract class exists to link together similar concrete types of objects. ATM example: Create an abstract class Transaction that is a superclass for Withdrawal, Deposit, etc. It can have an abstract responsibility "execute a financial transaction", that is implemented differently for each subclass
  • #15 The cards are either physical cards or electronic which are both inexpensive to erase. Don’t hesitate to make changes early in CRC cards, than make changes later in the code.
  • #35 Discovering Candidate ClassesRead Requirements DocumentsUnderline nouns and noun phrasesAdd them to candidate class listBrainstorm to find other potential classesClarifying the ScopeSelecting Core ClassesArchitectural DesignIdentify hot spotsUse appropriate design patternsTake advantage of existing software frameworksEliminate Unnecessary ClassesRemove ghost classesCombine synonyms Distinguish attributes from classes