Presentation is loading. Please wait.

Presentation is loading. Please wait.

Generalizable Element Namespace Model Element name visibility isSpecification Classifier isRoot Constraint Body Coming up: Class Syntax Basic Class Diagrams.

Similar presentations


Presentation on theme: "Generalizable Element Namespace Model Element name visibility isSpecification Classifier isRoot Constraint Body Coming up: Class Syntax Basic Class Diagrams."— Presentation transcript:

1 Generalizable Element Namespace Model Element name visibility isSpecification Classifier isRoot Constraint Body Coming up: Class Syntax Basic Class Diagrams CS/SWE 421 Introduction to Software Engineering Dan Fleck (Slides adapted from Dr. Stephen Clyde with permission)

2 Coming up: Class Names Class Syntax n A box divided into compartments –Name –Attributes –Operations –Responsibilities (rarely seen) –Used-defined compartments (rarely seen) Student major: String gpa: Real standing: String add(Class Section) drop(Class Section) -- The set of students known to the registration system -- An exception occurs if gpa falls below 2.0

3 Coming up: Exercise – Class Identification Class Names n The name should be a noun or noun phrase n The name should be singular and description of each object in the class n The name should be meaningful from a problem-domain perspective –“Student” is better than “Student Data” or “S-record” or any other implementation driven name n Avoid jargon in the names n Try to make the name descriptive of the class’s common properties

4 Coming up: Attributes Exercise – Class Identification n Identify meaningful classes in the Elevator System

5 Coming up: Attributes from an Analysis Perspective Attributes n Attributes represent characteristics or properties of objects n They are place holders or slots that hold values n The values they hold are other objects n The name of an attribute communicates its meaning n An attribute can be defined for individual objects or classes of objects –If defined for a class, then every object in the class has that attribute (place holder)

6 Coming up: Attribute Syntax Attributes from an Analysis Perspective n An attribute relates an object to some other object n It has the same semantics as an association joe: Student name: String = “Joe Jones” joe: Student Joe Jones : String Is basically the same as... name 1

7 Coming up: Operations Attribute Syntax visibility: public “+”, protected “#”, or private “-” name: capitalize first letter of each word that makes up the name, except for the first multiplicity: number, range, or sequence of number or ranges. type: build-in type or any user-defined class initial-value: any constant and user-defined object property-string: e.g, changeable, addOnly, frozen [visibility] name [multiplicity] [:type] [=initial-value] [{property-string}]

8 Coming up: Operation Syntax Operations Student major: String GPA: Real standing: String add(Class Section) drop(Class Section) Class Section name: String capacity: Integer add(Student) drop(Student) checkPrerequisites(Students) Prerequisite <has takes> Course

9 Coming up: Type of Relationships in Class Diagrams Operation Syntax visibility: “+”, “#”, “-” name: verb or verb phase, capitalize first letter of every word, except first parameter-list: coma separated list of parameters return-type: primitive type or user-defined type property-string: isQuery, sequential, guarded, concurrent [visibility] name [(parameter-list)] [:return- type] [{property-strong}]

10 Coming up: Associations Type of Relationships in Class Diagrams Relation A consolidated snippet of the UML Meta-model Association Generalization Dependency Aggregation Binary AssociationN-ary Association

11 Coming up: Associations Associations n An association is a structural relationship that specifies that objects of class may be connected to objects of another class n Meaning from three perspectives –Analysis: Links between objects –Specification: Obligation to provide a connection between objects –Implementation: Object pointers, references, linking structures, etc.

12 Coming up: Association Names Associations Student Class Section Course Semester Instructor Department takes> is registered for> teaches> sponsors> <works for is instance of> is held during>

13 Coming up: Navigation Association Names n Associations may be named –The names should communicate the meaning of the links –The names are typically verb phases –The name should include an arrow indicating the direction in which the name should be read –The direction on the name does NOT change navigability!

14 Coming up: Navigation Navigation n The navigation of associations can be –uni-directional –bi-directional –unspecified Class Section Course Instructor Department teaches> sponsors> <works for is instance of>

15 Coming up: Generalization Navigation n The navigation of association without an arrowhead is assumed to be undefined n Navigation has less value when modeling from a conceptual perspective –Why? n Navigation is more important from specification and implementation perspectives –Why?

16 Coming up: Exercise – Simple Associations Generalization n Generalization is another kind of relationship in UML n In a Java implementation what is this? StudentPerson Graduate Student

17 Coming up: Class Diagrams Exercise – Simple Associations n From an analysis perspective: –Identify meaningful associations and generalization/specializations among classes in the Elevator System

18 Coming up: Multiplicity Constraints Class Diagrams n Class Diagrams describe –the types of objects in a system –their properties (attributes and operations) –relationships between objects n They can also include –Grouping concepts like packages –Constraints –Various kinds of annotations

19 Coming up: Questions Multiplicity Constraints Student Class Section Course Semester Instructor Department takes> is registered for> teaches> sponsors> <works for is instance of> is held during> 1..* 1 1 1 0..8 0..* 0..61..3

20 Questions n From the previous diagram –How many classes can a student take? –Do you have to be registered in any classes to be a student? –Do I need to teach this class to be an Instructor? Do I need to teach ANY classes? –Can a class have no students? Is that valid? Coming up: Multiplicity Constraints

21 Coming up: Dependencies Multiplicity Constraints n A multiplicity constraint can be –a single number –a “*”, meaning an arbitrarily large number or simply “many” –a range, denoted by “min..max” –a sequence of single numbers and ranges 1..2,7,10-20 This is also called the cardinality constraint

22 Coming up: Dependency Relationship Dependencies Relation A consolidated snippet of the UML Meta-model Association Generalization Dependency Aggregation Binary AssociationN-ary Association

23 Coming up: Dependencies Dependency Relationship n It says that one modeling component “uses” another. n If the later changes then, the former may have to change as well

24 Coming up: Aggregations (is part of) Dependencies n Syntax: –a dashed link with an straight-line arrowhead point to a component on which there is a dependency n Dependencies can be defined among: classes, notes, packages, and other types of components n Can dependencies go both ways? n Any problems with having lots of dependencies?

25 Coming up: Aggregation Aggregations (is part of) Relation A consolidated snippet of the UML Meta-model Association Generalization Dependency Aggregation Binary AssociationN-ary Association

26 Coming up: Composition (very similar to aggregation) Aggregation n Aggregation: is a special kind of association that means “part of” n Aggregations should focus on single type of composition (physical, organization, etc.) 1 1 * 4..* 1 1 1 1 1..3 1 0..91 Pizza Order Slice Crust Sauce Serving Cheese Serving Topping Serving

27 Coming up: Lets look at BookstoreExample4.jpg Composition (very similar to aggregation) n Think of composition as a stronger form of aggregation. Composition means something is a part of the whole, but cannot survive on it’s own. BuildingRoom

28 Lets look at BookstoreExample4.jpg n Does John McCain (who has 7 houses) have a problem using this system? n If Barack Obama decides to create a Federal sales tax, how would we change the system? n Why is there a display method in Item, Book, MusicCD and Software? n An ItemOrder is part of how many Orders? n Can you explain how a search works using this diagram? Coming up: Class Exercise

29 Class Exercise n Lets create the WeGrow class diagram Coming up: Safety System Example

30 Safety System Example n A safety software system for housing areas: –enables its owner to configure it during installation, –controls through its sensors the environmental areas against fire and burglary and –interacts with the owner through the keypad of the system control panel. n During installation, the system programming and configuration is carried out by using the numerical and functional keys of the control panel. Each sensor in the system is identified by a number and a type (fire or burglary). The system stores two passwords (each of them is up to six digits) used for the system activation/deactivation and a telephone number used for emergency calls when an alarm event arises. The system polls the fire sensors for M seconds, then disables them for other N seconds. After that, the system resumes the same cycle. The Ready indicator is lighting when the sensors are polled and is turned o ff when the sensors are disabled. When a sensor indicates an event, the system launches an alarm signal. After K seconds, the system calls the security forces office and provides it with information about the event nature and location. In order to log in, the owner enters the password and presses Enter. If any of the six digits is wrong the password is ignored by the system and the sensors’s state doesn’t change. The owner can cancel the password with the Clear key. If a sensor is activated, the system is armed and the Armed indicator on the control panel is turn on. In the case of the sensor deactivation, the Armed indicator is turn o ff. Moreover, the system logs all events. Each logged event is characterized by its type and the date and time of its occurrence. The event list can be delivered by pressing the MEM key. Coming up: Validating a class diagram Example specification from: http://www.emis.de/journals/ASUO/mathematics/pdf3/bogdan.ps

31 Coming up: Some User Stories for WeGrow Validating a class diagram n One of the most important, and often overlooked issues is how to validate a class diagram. (Usually best for a diagram at the implementation perspective) n Given a specification or a use-case, can you look at the class diagram and use attributes and methods to “execute” a use case? n Lets try it for the WeGrow class diagram

32 Some User Stories for WeGrow n As an analyst I need to get a report on sales statistics on a per store basis. n As a store manager I want to change prices for an item in my store only. n As a sales clerk I want to determine the closest store that has the item in stock and request a transfer of the merchandise Coming up: Questions

33 Coming up: More Questions Questions n What’s the difference between an attribute and an association with another class? For example, should “grade” be an attribute or a link to another class called “Grade”? n When during the software engineering life cycle should you build classes diagrams?

34 Coming up: What’s important More Questions n How do you know when a class diagram is complete? n How can you manage change control on all the class diagrams for project? n What do you do with class diagrams after a system has been built and delivered?

35 What’s important n Understading the 3 main parts of the class box n Generalization/Specialization n Associations and multiplicity constraints n Aggregation (and composition) understand how to use them, but don’t worry about the differences between them – too subtle n Knowing these you should be able to validate a class diagram Coming up: Bonus Slide!

36 Bonus Slide! n If you’re interested in Auto-generating UML, Netbeans has an option to do it. –Install the UML plugin –Right-click on a project –Choose “Reverse Engineer” –Go to the new UML project –Select a package and choose to generate a new UML diagram Coming up:

37 n REMOVED SLIDES n These are things I removed over time from this lecture because they are less common or needed for a basic understanding. n Read if you want. Coming up: Class Diagrams

38 Class Diagrams n Class Diagrams are like the paragraphs of a technical paper –each diagram should focus on a specific topic –a diagram provides supporting detail for the main concept(s) that it is trying to communicate –the level of the abstraction used in the diagrams should be consistent n Together, all the diagrams for a system comprise a “model” of that system

39 Coming up: Exercise – Attributes Class Diagrams n Pitfalls of Class Diagrams: –Using class diagrams alone can cause developers to focus too much on structure and ignore behavior –Using the wrong (or a mixed) perspective can lead to misunderstanding –Using the wrong level of abstraction can be confusing to the target audience –Using mixed levels of abstraction can reduce the usefulness of diagram

40 Coming up: Operations Exercise – Attributes n Describe meaningful attributes for the key classes in the Elevator System

41 Coming up: Attributes from an Implementation Perspective Operations n Meaning from three perspectives –Analysis: Ways in which objects interaction –Specification: An obligation to provide a service –Implementation: A function member, a method

42 Coming up: Return to Objects – Object Syntax Attributes from an Implementation Perspective n Attributes from an implementation perspective are similar data members in C++ or Java n They are place holders with value semantics n Each object can have different values n Constraints can be placed on the attributes to restrict how and when the values can be changed

43 Coming up: N-ary Associations Return to Objects – Object Syntax n Object syntax is similar to class syntax, except –the name identifies specific or generic object –the name includes the class that the object belongs to n Remember, individual objects are instances of classes joe: Student major: String = “CS” gpa: Real = 4.0 standing: String = “” add(Class Section) drop(Class Section)

44 Coming up: More Questions N-ary Associations n Associations can connect more than one class n Notation: n How should we go about naming an n-ary association? StudentAdvisor Major

45 Coming up: Attributes from a Specification Perspective More Questions n How does one decide how to break up the responsibilities of a system into meaningful classes? n How do you know if you have identified the best classes for a system? n How do you know where in a class hierarchy a particular attribute or operation bests fit?

46 Coming up: Generalization Attributes from a Specification Perspective n An attribute represents an obligation to provide or manage a certain (single) piece of information Student major: String gpa: Real standing: String n For example, each Student object must be able to encapsulate a major, a GPA, and a standing

47 End of presentation Generalization n From a specification/implementation perspective, generalization can represent sub- typing, inheritance, type capability, and substitutability (depends on the language) Student major: String GPA: Real standing: String add(Class Section) drop(Class Section) Person name: String address: String changeAddress(new_address)


Download ppt "Generalizable Element Namespace Model Element name visibility isSpecification Classifier isRoot Constraint Body Coming up: Class Syntax Basic Class Diagrams."

Similar presentations


Ads by Google