31

The three links Association, Aggregation and Composition form a kind of scale on how closely two classes are related to each other. On the one end of the scale, there is Association, where objects of the two classes can know about each other, but they do not affect each others lifetime. The objects can exist independently and which class A object knows ...


21

These functions both have to do with collisions, but what they do is very different, so giving them names that more clearly describe what they actually do will make it easier for future developers to understand the difference without having to look at the logic inside. The method that checks if the object is colliding with another object could be called ...


13

In order to better discuss the image, I annotated your image with some numbers. Hopefully this will help me be more clear in my writing. There are really three types of lines used here - association (1), composition (4->2), and inheritance (3). A solid line connecting two classes, such as between Client and BookComponent is simply an association ...


12

In a class diagram, you don't show the act of instantiation. That is something that a sequence or communication diagram would show. Class diagrams show the static structure of a system. If a class A "depends on" a class B, then you could look at the association and dependency relationships. Dependency is the weaker of the two and is usually used if the ...


12

Exactly those classes which are necessary to understand the aspect of the system which that particular class diagram depicts. It could be the entire domain model, or all classes that make up the external API of a particular layer or subsystem, or whatever you think is important. But note that class diagrams are not the only type of diagram, nor the most ...


9

It makes no sense to say that a class can implement an interface. Either it does or it doesn't, and that's determined as the code is written. Specific instances (users) can't make that decision for themselves, although they can set an IsAdministrator flag instead. If the IsAdministrator flag is insufficient, then (as @superM said) the design you want is ...


9

No, it's much faster to write code than to draw diagrams on a computer. To generate a Java class from a diagram you would have to draw the diagram, and then type in most of the code anyway. Sure, you might not have to type get/set methods, but Lombok does a better job of solving that problem. For example, it's much easier to simply type "class X ...


9

Composition is when an object A contains object B and the object A is also responsible for creating the object B. Composition relationship We have a class A which will be used by class B. final class A { } There are multiple options as how the composition may look. Direct initialization composition: final class B { private $a = new A(); } ...


8

A server or database doesn't go into a class diagram. A class diagram, at the highest level, shows the classes and their relationships with each other. Adding more detail would first indicate public members, and even more detail would indicate private members of the class. You may show classes that interact with the database (your data model, as an example), ...


8

You're partially right: the problem exists in the case of the multiple inheritance too, but can easily be solved in some languages; diamond, on the other hand, cannot be solved that easily. In C#, multiple inheritance is forbidden, but a class can implement multiple interfaces. Imagine that the class Example implements IModifiable and ITransformable. Those ...


7

You can add an open arrow head to the composition or aggregation line, pointing toward the child to indicate directionality in the relationship. If the child knows about the parent, then simply don't include an arrow at all. I believe this works, because composition is a stronger form of an association link. The diamond indicates a composition or aggregation ...


7

I think the last few years have shown a preference for using class diagrams to document existing code as opposed to generating code. Diagrams give the reader of the code a quick look at the overall structure of the systems in terms of its classes and relationships. Of course, the successful use of diagrams is dependent on the diagrams being kept in sync ...


7

System architecture describes the components of the system. For example you might have an order entry system that consists of: Web Front End, Business Layer Service, and Data Store. So, you should a high level diagram showing this. Software application architecture describes the architecture of a particular component. For example, one of the ...


7

In a class diagram, you don't typically show the functionality of a particular method. That's not the purpose of a class diagram. You're right that you can use Object Constraint Language or pseudocode in a note, but I don't think this is done often. Consider the mode in which you are using UML. If you are using UML as a blueprint, you're going to want the ...


7

The only principle which is not respected here is the Interface Segregation Principle: E-book inherits stock and replenishStock() which are absolutely useless for an electronic book. If you want to have a proper segregation of interfaces, you'd need something like the following, where Book describes a content, and PaperBook and e-Book correspond to ...


6

[Disclaimer: I'm not a UML jockey, so don't take my word for it.] I think, it would look like this. Some details omitted for brevity.


6

UML is not one of these mathematical computation models that try to achieve completeness with a minimal set of rules(like Turning machines or lambda calculus). UML is a visualization of software architecture and flow. It is not used for proving - it is used for understanding. Yes, using 1..* forces a child to exist for the duration of it's parent's lifetime(...


6

Can a class inherited an implementation of interface ? The interface realization expresses that a class X implements a an interface I. Class X can then, like any other class be specialized further by letting other classes inherit from it. Your UML diagram You could therefore have an interface Contract, and have several implementation such as ...


5

Show them if and only if they help understanding whatever aspect of the system that diagram is supposed to show. UML is a tool for communication. If you can't say what a diagram communicates, you shouldn't have that diagram.


5

You can draw an UML sequence diagram out of this easily, but a class diagramm won't tell you much, except for some logical errors. Let's draw up a sequence diagram first: Now, let's remove Factory for a moment, what do we have? Hmm, are we sure we're missing something? Basically all your Factory module does is, it shortens a namespace into its last part. ...


5

I annotate the line with "*..*". For 1-to-many it would be "1..*". It's a standard way of denoting multiplicity. http://en.wikipedia.org/wiki/Cardinality_%28data_modeling%29 http://www.agilemodeling.com/artifacts/classDiagram.htm


5

What you want is a Decorator. An Administrator would be a subclass of User, and its primary member attribute would be a User object. Thus a Student Adminstrator would be an Administrator containing a Student (which is a subclass of User, right? The Administrator-specific attributes are set in the Adminstrator class, with the User methods passed through ...


5

The level of abstraction provided by Entity Relationship Diagrams created with modeling tools, the entity model provided by EF, and UML class diagrams is almost the same. When I create my POCO entities I generally put them in my Model project with my other domain classes, and so a class diagram of the domain model contains the same POCO entities found in the ...


5

Your external API (the connection to the content management system) is not a class, it's an interface. As illustrated in this Stack Overflow question, it would look something like this:


5

I am doubting what I should name my association. Should it be "a flight has * stewards"? Or should it be "a steward works on many flights"? Usually, the more specific you can name your association, the better, because a more specific name conveys more information. On the other hand, if you are using a directional association (you put an arrowhead on one ...


5

I'm sorry, but I have to inform you that there is no "correct" or "wrong" in class designs. You can do "wrong" UML by drawing strange unicorns into the diagram, but whether your design is good enough depends on a large amount of different factors. It's not as easy as simply telling us one requirement and expect to be able to derive a design from that. The ...


5

However, I am still unsure how or where I am supposed to describe the functionality that a method of a class offers. This is a valid concern. I should be able to look at your UML diagram and have a fairly good idea what the methods do. In code, I would simply put a docblock above a method in which I describe that method's purpose. Where would I put that ...


4

Isn't using an interface for this type correct? Using an interface in this case would work, but you would have to duplicate behavior between Directory and File (like having a maximum of 256 chars for the name). You would be better off making FileSystemElement an abstract class (assuming your language of choice supports it) Which also answers your second ...


4

Subclasses and subtypes bring a lot of baggage with them in the form of inheritence and the desirabality of supporting the Liskov Substitution Principle. It would be pretty foolish to start creating subclasses simply to support an arbitrary naming convention. It's unclear why you would need separate classes for what you are describing. How is StandLeft ...


4

I work at a Fortune 100 company as a Senior Architect. We're about as uptight about UML as you find in the industry, and we don't worry about these kinds of things. Basically, if including an external system (typically using a separate package notation) helps explain something, then include it. If it is just there for some insignificant corner case that ...


Only top voted, non community-wiki answers of a minimum length are eligible