UML Class Diagrams Overview

RapturousMiracle avatar
RapturousMiracle
·
·
Download

Start Quiz

Study Flashcards

26 Questions

What is the consequence of choosing aggregation when a client gets a reference to the position or velocity of a projectile?

The client can change these quantities without asking the projectile.

Explain the concept of Composition in object-oriented programming.

An object of type X that is composed of an object of type Y means X has-a Y object and owns the Y object, having exclusive access to it.

What does it mean when it's said that the X object has exclusive access to its Y object in Composition?

It means that the X object will generally not share references to its Y object with clients.

Why is a deep copy required in Composition when a constructor has a Y parameter?

A deep copy is required to ensure that the X object has exclusive access to its Y object.

What must a default constructor do in Composition?

The default constructor must create a suitable Y object.

In Composition, what should a constructor do when it has a Y parameter?

The constructor must first deep copy and then validate the Y object.

What is a UML class diagram used for?

A UML class diagram is used for visualizing the design of a software system.

What does an open arrow at the end of a dashed line in a UML class diagram represent?

A dependency relationship.

How is aggregation different from composition in terms of ownership?

Composition implies ownership, while aggregation does not imply ownership.

Give an example of aggregation with a Person class.

In a Person class, having a name and a date of birth as attributes.

What relationship does association model in UML class diagrams?

The has-a relationship.

Explain the 'lollipop' notation used in UML class diagrams.

It indicates that a class implements an interface.

What does a solid line connecting two classes in a UML class diagram represent?

An association relationship.

What type of relationship is dependency in UML class diagrams?

Dependency is the weakest relationship between classes.

How is aggregation different from association?

Aggregation and composition are stronger forms of association, with ownership implications.

What happens in aggregation when a client modifies an attribute of the shared object?

The modification is reflected in all instances sharing the object.

What is a privacy leak in a class?

A privacy leak occurs when a class exposes a reference to a non-public field that is not a primitive or immutable.

How can a privacy leak affect the composition of an object?

A privacy leak can break composition as the object no longer owns its attribute.

What are the consequences of a privacy leak in a CreditCard class?

A client could set the expiry date of the CreditCard to before the issue date.

Why is it important to prevent privacy leaks in a Period class?

To ensure that the end of the period cannot be set before the start of the period.

What are the key points in the recipe for immutability in Java?

Do not provide methods that alter the object's state, make fields final and private, prevent inheritance, and prevent clients from obtaining a reference to mutable fields.

Why should a class prevent clients from obtaining a reference to any mutable fields?

To maintain the immutability of the class and prevent unexpected changes to its state.

How does using composition in a Period class help prevent privacy leaks?

By creating new Date objects in accessors and mutators instead of returning references to the original Date objects.

What is the difference between aggregation and composition when dealing with arrays?

Aggregation with arrays of reference types can lead to complexity, while composition involves better ownership and control over array elements.

How can a privacy leak affect the object's class invariants?

A privacy leak can make it impossible to guarantee class invariants.

What is the risk of not preventing privacy leaks in a Java class?

The object's state can become inconsistent and other objects may control its data.

Learn about Unified Modelling Language (UML) class diagrams, which are used in software engineering to visualize the design of a software system. This quiz covers the structure of a class including its name, fields, and methods.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free
Use Quizgecko on...
Browser
Browser