150 likes | 332 Views
Design Class Diagrams & Intro to Sequence Diagrams. CIS 480, Spring 2012. Adding Objects at the Model Level. Can Add an Object to the MODEL without putting it in a diagram Right Click on Top package for the model & from the new menu select the type of object. Then complete its specifications .
E N D
Design Class Diagrams& Intro to Sequence Diagrams CIS 480, Spring 2012
Adding Objects at the Model Level • Can Add an Object to the MODEL without putting it in a diagram • Right Click on Top package for the model & from the new menu select the type of object. Then complete its specifications
Relationship of Objects with and Diagrams • Creating an object (Class, Actor, Use case, etc.) in a diagram adds the objects to the model to which the diagram belongs. • Deleting an object from a diagram does not delete it from the model • It must be deleted from the model • The attribute and methods of classes also become Objects Under the Class in the Model • And can be edited from the model
Adding Operations (Methods) to a Class • Double click class to edit it • Pick operations from the left side menu • Enter a method name • Can select a return type, change visibility, etc. • Click on properties button • In Operation Properties Dialog box pick Parameters from left side menu • Enter Parameter name, select data type, etc.
Method Display in Class Diagram • Once specified, the full method signature is displayed in the class diagram and • The method and its parameters are elements under the class in the MODEL NOTE: could pick Methods in top dialog box on the pervious slide and enter a method body
Class Stereotypes • Can select a stereotype for a class in the class dialog box • Stereotype then appears in front of the Name in the class diagram • Controller & Interface not available stereotypes, but • Can specify a Utility or Implementation Class Stereotype
Collection Classes • When we want the system to display a list of objects for a user to choose from, we will need to create a collection class e.g. CustList might be a collection Class for the Customer class • The collection class will have an array of objects of the base class as one of its attributes
Selecting an Object as a data type • You may need to make the Type column wider in the Attributes dialog box • Then you will see all of the Classes you have created in the set of types that can be chosen. • I used 0..* multiplicity to suggest an array
Methods – Instance & Class • We want this collection object to display its collection of customers • Specify GetCusts as an operation (Method) • Return type is a CustList Object • Click Properties button on Right to display Properties Dialog for this method • Owner Scope specifies whether it is an instance or a class (classifier) method • We want the is classifier option in this case
Overloaded Methods • As in programming, can have overloaded methods. • Sometimes we want a list of all customers, • Sometimes the user selects a customer type and we retrieve only a list of customers of that type. • We can store 2 version of the GetCust method one with no input parameter & one that takes a CustType value as input and returns only customers of that type.
Design Sequence Diagrams • As we add object Lifelines to a sequence diagram in the design phase, we can and often do add an object of a class that has been created in the model. • Pick the class from the Classifier drop down on the object’s dialog box and • Name the Object the Classname1 or ClassnameA Sequence diagrams operate on Object instances versus the Class as a whole.
Adding a Class in a Sequence Diagram • If we discovery the need for a new class while specifying a sequences diagram • (after double clicking) Select New on the initial dialog box • This pops up the main dialog box for creating a class • Can specify it, add attributes & operations, etc. as with any class • The class is added to the model, but not to any diagrams • Must still name the object in the top dialog box here
Adding Methods in the Sequence Diagram • When adding a message, we name it • Then can click the new button next to Operation to display an Operation dialog box • Use the same name here and can specify a return type and parameters • This creates a method of the class the message is going to Appears in the model, not automatically added to class diagram
Selecting an Existing Method as the Message • When sending a message to an object of a class that has methods, • Message name is = to first method name of class by default • Can choose the method to be used from the Operations drop down • Or can click to add a new method if needed. • If a new method created it is added to model • Will also be added to the display of the class in any diagrams it has been included on