I put an answer after @Christophe did because in (the first version of) his proposal there are exceptionally some problems. Show
An order contains at least one dish. But an order is not composed of dishes, so there is no composition, and for me nor even an aggregation. A dish is made from at least one product, using a given quantity of them. Depending on the product the quantity is a volume (for instance for a liquid), or a weight (for instance for butter) or a number (for instance for egg), etc. For that you can use a class-relation. The relation cannot be a composition because a given product can be used for several dishes. A menu contains a least one dish, but a given dish can be used in several menus so a composition cannot be used. In my diagrams I use an aggregation but perhaps this is not a good idea. Supposing you always need to have specialized classes for Menu and Dish you can have : but I am not sure you always need these specializations, so Dish and Menu are not abstract even they can have specializations, and you can have : (I suppose a dish is always part of at least one menu, this is a choice, so a 'preparation' made by cook but not part of a menu is not a dish) As @Christophe said in a remark the customer can ask for some specific instructions (medium versus bloody for the meat etc), that can be supported by a class-relation : IntroductionUML (Unified Modeling Language) is a graphical language for modeling the structure and behavior of object-oriented systems. UML is widely used in industry to design, develop and document complex software. This page will focus on creating UML class diagrams, which describe the internal structure of classes and relationships between classes. For additional information beyond the usual suspects (your textbook and Wikipedia), see UML Basics: The Class Diagram. ClassesA class diagram contains a rectangle for each class. It is divided into three parts.
For example, a Person class and a Book class might be modeled like this. This indicates that a Person object has private fields named name and birthDate, and that it has public methods named getName, setName and isBirthday. A Book object has private fields named title and authors. A Book object also has public methods named getTitle, getAuthors and addAuthor. The examples below also model a Person class and Book class, but only shows fields or methods as needed for illustration. Use RelationshipsOften, objects and/or methods of one class use objects/methods from another class. For example, a person might read and/or own a book, and these relationships might be modeled in the UML diagram, so that they will be implemented in the corresponding program. UML class diagrams include the following types of use-relationships, in order from weakest to strongest.
Inheritance RelationshipsThe inheritance relationships in UML match up very closely with inheritance in Java. When a class inherits another class it is required to use all the data?what is the relationship called in which one object is a specialized version of another object? When a class inherits another class, it is required to use all the data attributes and methods of the superclass.
What does a subclass inherit from a superclass?A subclass inherits all the members (fields, methods, and nested classes) from its superclass. Constructors are not members, so they are not inherited by subclasses, but the constructor of the superclass can be invoked from the subclass.
Which method would you use to determine whether a certain substring is the suffix of a string?The endsWith() method determines whether a string ends with the characters of a specified string, returning true or false as appropriate.
What gives a program the ability to call the correct method depending on the type of object that is used to call it?Polymorphism is a feature of object-oriented programming languages that allows a specific routine to use variables of different types at different times. Polymorphism in programming gives a program the ability to redefine methods for derived classes.
|