1 / 103

Introduction to advance class modelling

Introduction to advance class modelling. Enumerations Multiplicity Scope Visibility. Advanced Object & Class Concept. An enumeration is a data type that has finite set of values: For ex. Enumeration often occur and are important to users.

avery
Télécharger la présentation

Introduction to advance class modelling

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to advance class modelling

  2. Enumerations Multiplicity Scope Visibility Advanced Object & Class Concept

  3. An enumeration is a data type that has finite set of values: For ex. Enumeration often occur and are important to users. i.e. it display only the possible values or users are restricted to access only allowed values or data. Do not use generalization to capture the values of an enumerated attributes <<enumeration>> week Sunday Monday Tuesday ……. Saturday Calendar week: Week Enumeration

  4. An enumeration  list of values Generalization  Structuring the description of objects. Ex. We are not introducing generalization for “Card” Class because most games do not differentiate the behavior of “Suit”. <<enumeration>> Suit Spades Clubs Hearts diamonds Card suit:suit rank: rank

  5. Top section: Write keyword enumeration in between “<<>>” above enumeration name. Second section : List the enumeration values. UML notation

  6. Multiplicity is a constraint on the cardinality of a set. Multiplicity for an attribute specifies the number of possible values for each representation of attributes. Common specifications are Mandatory single value [1] An optional single value [0..1] Many[*] It specify whether an attribute is mandatory or optional It indicates if an attribute is single valued or can be a collection. Multiplicity

  7. If not specified, it is assumed to be a mandatory single value[1] Person name: string[1] address:string[1..*] birthdate:date[1]

  8. It indicates if a feature applies to an object or a class. You should avoid attributes with class scope because they can lead inferior model. It is better to model group explicitly and assign attributes to them. Person name Scope PhoneMessage source maximumDuration maxDaysRetained dateRecorded timeRecorded priority PhoneMailBox 0..1 * 1 maxMessageCount phoneNumber password * owner {ordered} 1 *

  9. Upper model is inferior because the maximum duration, maximum day retained and maximum message count have a single value for the entire phone mail system. It is acceptable to use an attribute with class scope to hold the extent of a class ( Set of objects for a class) PhoneMessage Person dateRecorded timeRecorded priority PhoneMailBox MailCategory phoneNumber password name maxMessageCount maximumDuration maxDaysRetained source 0..1 * 1 * owner {ordered} 1 * * owner 1

  10. It is also acceptable to define operations of class scope. It is convenient to define class scoped operations to provide summary data.

  11. Visibility refers to the ability of a method to reference a feature from another class and has the possible values of Public, Protected Private Package Public features: Any method freely access Protected features: only methods of the containing class and its descendant via inheritance can access Private features: only methods of the containing class can access. Package features: Methods of classes defined in the same package as the target class can access. Visibility

  12. UML denotes visibility with a prefix. Character “+” precedes public Character “-” precedes private Character “#” precedes protected Character “~” precedes package Several issues when choosing visibility Comprehension You must understand all public features to understand the capabilities of a class. Others are merely an implementation convenience.

  13. Extensibility Many classes can depend on public methods, so it can be highly disruptive to change their signature. Fewer classes depend on private, protected, and package methods, there is more latitude to change them. Context Private, protected and package methods may rely on preconditions or state information created by other methods in the class. A private method may calculate incorrect results or cause the object to fail.

  14. A binary association has two ends, a ternary association has three ends and so forth. Few properties: Association end name: An association end may have meaningful name. Names clarifies multiple references to a class and facilitate navigation Multiplicity: Can specify multiplicity for each association end. Ordering: Objects for a “many” association end are usually just a set. Bags & Sequences: Objects for a “many” association end also be a bag or sequence. Qualification: One or more qualifier attributes can disambiguate the objects for “many” association end Association ends

  15. Aggregation: It may be an aggregate or constituent (element) part. Only binary association can be a aggregation: One association end must be an aggregate Other must be a constituent Changeability: It specifies the update status of an association end. Navigability UML shows navigability with an arrowhead on the association end attached to the target class. Arrowheads may be attached to zero, one or both ends of an association. Visibility Similar to attributes and operations, association ends may be public, protected, private or package. Additional properties

  16. N-ary associations mean associations among three or more classes. Ex. Programmers use computer languages on projects. UML notation: It is diamond with lines connecting to related classes. If the association has a name, written in italics next to the diamond. Note: Avoid n-ary associations – most of them can be decomposed into binary associations, with possible qualifiers and attributes. N-ary Associations Project Language * * * programmer Person

  17. N-ary association can have a name for each end just like binary associations. You can not traverse n-ary associations from one end to another as with binary associations. DeliveredCourse roomNumber Professor * * * Textbook Semester * * ListedCourse

  18. Ex. A professor teaches a listed course during a semester. The resulting delivered course has a room number and any number of textbooks. Programming language can not express n-ary associations. So you need to promote (support) n-ary associations to classes. When you promote n-ary associations to a class, might change the meaning of a model. An n-ary associations enforces that there is most one link for each combinations. Ex. For each combinations of professor, semester and ListedCourse there is one DeliveredCourse So if you were implementing below fig. special application code would have to enforce the uniqueness of Professor + Semester + ListedCourse.

  19. DeliveredCourse roomNumber Professor 1 * 1 * * * Semester Textbook * 1 ListedCourse

  20. UML has two forms of part-whole relationships: Aggregation - A general form Composition – More restrictive.

  21. Definition: An aggregation as relating an assembly class to one constituent part class. An assembly with many kinds of constituent parts corresponds to many aggregations. For ex. College consists of students, professor, courses etc. Here college is assembly and the others are constituents. Therefore, college to student is one aggregation, college to professor is another aggregation. We define each individual pairing as an aggregation. So that we can specify the multiplicity of each constituent part within the assembly. Aggregation

  22. Aggregation is an special form of binary associations. Most important property of aggregation: Transitivity If A is part of B and B is part of C, then A is part of C. Antisymmetric If A is part of B, then B is not part of A. Aggregate operations imply transitive closure and operate on both direct and indirect parts.

  23. Aggregation is not an independent concept, it is a special form of association. If two objects are tightly bound by a part-whole relationship, it is an aggregation. If two objects are usually considered as independent and have linked, it is association. To find whether there is a aggregation or not, some tests includes: Use the phrase part of Some operations on the Whole apply to its parts Some attributes values circulate from whole to all or some parts. Aggregation v/s Association

  24. UML notation: • Like association, except a small diamond indicates the assembly end. • Decision to use aggregation is • Matter of Judgment • Arbitrary College Courses Professor Student

  25. Composition is a form of aggregation with two additional constraints. A constituent part can belong to at most one assembly. Once its assigned, it has coincident lifetime with the assembly. Composition implies ownership of the parts by the whole. Composition is convenient for programming Ex. Deletion of assembly object triggers deletion of all constituent objects. Aggregation v/s Composition

  26. UML notation: Composition is a small solid diamond next to assembly class. EX. A company consists of divisions, which in turn consists of departments. A Company is indirectly a composition of departments. 1 * 1 * Department Division Company 1 WorksFor * Person

  27. Propagation of operations • Propagation is the automatic application of an operation to a network of objects. When the operation is applied to some starting object. • Ex. A persons owns multiple documents. • Copy operations propagate from document to paragraph to characters. • Copying a paragraph copies all the characters in it. • Operation does not propagate in the reverse direction: A paragraph can be copied without copying the whole document.

  28. UML notation: Small arrow indicating the direction and operation name next to the affected association. Note: this notation is not part of the UML and is a special notation.

  29. An abstract class is a class that has no direct instances but whose descendant classes have direct instances. A Concrete class is a class that is instantiable; it can have direct instances. Only concrete classes may be leaf classes in an inheritance tree. Abstract Classes

  30. Baker and candelstickMaker are concrete classes because they have direct instances. Worker { note: listing of workers is incomplete} Baker CandlestickMaker Concrete Class: it can have direct instances.

  31. FullTimeEmployee and PartTimeEmployee are concrete classes because they can be directly instantiated. UML Notation: Abstract class name listed in italic font or may place keyword {abstract} below or after the name. Abstract Class and Abstract operation: it has not direct instances.

  32. An abstract class can define signature for an operation without supplying corresponding method. An abstract operation defines the signature of an operation for which each concrete subclass must provide its own implementation. A concrete class may not contain abstract operations. UML Notation: An abstract operation is designated by italics or the keyword {abstract}. Note: Abstract nature of a class is always provisional, depending on the point of view or application.

  33. It permits a class to have more than one superclass and to inherit features from all parents. More complicated form of generalization than single inheritance. Advantage is greater power in specifying classes and an increased opportunity for reuse. Disadvantage is a loss of conceptual and implementation simplicity. Multiple inheritance mean either the conceptual relationship between classes or the languages mechanism that implements that relationship. Distinguish between Generalization : conceptual relationship Inheritance : Language mechanism. Multiple Inheritance

  34. Common form of multiple inheritance is from sets of disjoint classes. Each subclasses inherits from one class in each set. Kinds of multiple Inheritance Employee employementStatus managerialStatus FullTimeEmp PartTimeEmp Manager IndividualContributor FullTimeIndividualContributor

  35. Here, FullTimeEmp and PartTimeEmp are disjoint; and Manager and IndividualContributor are also disjoint classes. We can also define additional combinations classes here like FullTimeManager, PartTimeContributor, PartTimeManager and FullTimeIndividualContributor. Each generalization should cover a single aspect (A generalization set name). Therefore, here class Employee has two aspect Employment Status Managerial Status

  36. So, FullTimeIndividualContributor inherits Employee features along two paths via employmentStatus and managerialStatus. Conflicts among parallel definitions create ambiguities. You should avoid such conflicts in models or explicitly resolve them. For Ex. FullTimeEmp and IndividualContributor both have attribute called name. FullTimeEmp.name could refer as person’s full name and IndividualContributor.name might refer as person’s title. Solution is restating the attributes of classes.

  37. Multiple inheritance can also occur with overlapping classes. Vehicle watervehicle landVehicle Car Amphibiousvehicle boat {overlapping, incomplete}

  38. AmphibiousVehicle is both Land and water vehicle. So there is a overlapping. UML uses constraint to indicate an overlapping generalizations set; Notation is a dotted line cutting across affected generalization with keyword in braces.

  39. Multiple Classification Definition: • One instance happens to participant in two overlapping classes.

  40. UML permits multiple classification but most OO languages handle it poorly. Fig. show that Person as an object composed of multiple UniversityMember object. This workaround replaces inheritance with delegation. This is not totally satisfactory, there is a loss of identity separates roles.

  41. Dealing with multiple inheritance is implementation issue but early restructuring of a model is often the easiest way to work around its absence. Two approaches make use of delegation, which is an implementation mechanism by which object forwards an operation to another object for execution. Restructuring technique Delegation using composition of parts Inherit the most important class and delegate the rest. Nested generalization Workaround

  42. Delegation using composition of parts You can recast superclass with multiple independent generalization as a composition in which each constituent part replaces a generalization. Single object having a unique ID by a group of related objects that compose an extended object. Inheritance of operations across the composition is not automatic. Composite must capture operations and delegate to appropriate part.

  43. Workaround for multiple inheritance - delegation • You need not create various combination as explicit classes. • All combinations of subclasses from the different generalizations are possible.

  44. Inherit the most important class and delegate the rest. • Maintain identity and inheritance across the most important generalization. • Reduce the remaining generalization to composition and delegate their operations. Workaround for multiple inheritance – inheritance and delegation

  45. Nested Generalization: • Factor on one generalization first, then the other. • This approaches multiplies out all possible combinations. • This preserves inheritance but duplicates declarations and code and violates the spirit of OO programming.

  46. There are several issue when selecting the best workaround. Superclass of equal importance Dominant superclass Few subclass Sequencing generalization sets Large quantities of code Identity

  47. Superclass of equal importance: If a subclass has several superclasses it may be best to use delegation and preserves symmetry in the model. Dominant superclass: If one superclass clearly dominate and others are less important, preserve inheritance through this path. Few subclasses: If the number of combinations is small, consider nested generalization otherwise avoid. Sequencing generalization sets. In a case of generalization, factor on most important criterion first, then second most and so forth.

  48. Large quantities of code: Try to avoid nested generalization, in a case of duplicate large quantities of code. Identity: Consider the importance of maintaining strict identity. Only nested generalization preserves this.

  49. Metadata Definition • Metadata is data that describes other data. • For ex. A class definition is metadata. • Models are inherently metadata, they describe the things being modeled.

  50. A car model describes many physical cars and holds common data. A car model is metadata relative to a physical car, which is data.

More Related