Lecture 6: Composition & Aggregation

Ace your homework & exams now with Quizwiz!

What's composition?

- A class may be composed of one or more other classes - i.e. it has fields of another class type

What is aggregation?

- An aggregation is typically used when a class acts as a container to hold a collection of objects.

What's the difference between composition and aggregation?

- Composition usually implies a single object of another class is stored. - Aggregation implies storing a collection of objects of another class.

Where dependence most often exist? Example?

- Dependencies most often exist within methods when an object of another class is either passed in as a parameter or declared locally within it. E.g. A class may have a method that uses the Math class to assist with a calculation.

What's delegation principle?

- When classes use or store other objects they can reuse methods belonging to those objects - this principle is called delegation. - Delegation can be used with compositions but is even more commonly used with aggregation

What is dependency?

- When one class 'uses' another class internally, there is said to be a dependency. - A class will use one or more objects of another class type.

What's the common way to decide if sth is composition? Could you give an example (draw diagram)?

A common way to decide whether an association is a composition is if you can use "has-a", e.g. An Employee has-a Name and a Date of employment.

What is association?

If one class uses or requires features of another class then we say they are 'associated'.

What types of associations there are? (the ones that we cover in the module)

There are different types of association, most notably dependency, composition and aggregation.


Related study sets

Quiz 9 - Part 1 - Digestive System Disorders (Ch.17)

View Set

Musculoskeletal Alternations Study Guide Questions

View Set

Nu424 EKG, IV fluids, Hemodynamics prepu

View Set

Chapter 59: Assessment and Management of Problems Related to Male Reproductive Processes

View Set

Practice Test 2 Comm 1402 Chapter 3, 5,8,11,15

View Set