Section 12 Chapter 68 - Object Oriented Design Principles Flashcards

1
Q

Aggregation

A

Occurs when a class is a container of other classes but these contained classes can exist without their container. The container is said to be an aggregation of its contained objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Composition

A

Occurs when a class is a container of other classes and these contained objects cannot exist without their container. If the container is destroyed then so are all the objects contained in it. The container is said to be a composition of its contained objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

UML symbol for aggregation

A

Line between two objects with a white diamond at the container

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

UML symbol for composition

A

Line between two objects with a black diamond at the container

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Polymorphism

A

A pattern in OOP where classes can have different functionality while sharing a common interface, commonly achieved by child classes overriding the methods of their super class. It can also be described as the ability of a programming language to process objects differently depending on their class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Overriding

A

Defining a method with the same name and arguments as that of a method in the parent class, when the class in question inherits from the parent class. If the method of this name is called from an instance of the child class, the code for the overriding method will be executed rather than the code of the parents method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Why OOP is used (6)

A
  • Forces designers to go through more extensive planning
  • Due to encapsulation, individual classes can be tested independently
  • Abstraction: Once a class is created the knowledge of how it is exactly implemented is not needed
  • New objects can be created without affecting old ones
  • Re usability since basic objects (such as a graph or a tree) can be used for many different things
  • Easier to maintain as errors tend to be more localised
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

“Favour composition over inheritance”

A

Composition is generally preferred to inheritance since it allows greater flexibility, since composition is a less rigid relationship. For instance if classes B and C both inherit from class A, it would then not be possible to create a class D which is a combination of classes B and C using only inheritance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

“Programming to an interface”

A

In the case that many, often unrelated, classes need to be able to respond to the same messages it can be useful to implement an interface. An interface is a collection of abstract methods that classes can implement and then define appropriately. Polymorphism can be used in this case since all these classes will have a common set of methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

“Encapsulate what varies”

A

A strategy used to reduce maintenance. When something changes in a program (for instance in different specifications) the part that changes should be encapsulated so that only the inner workings of that part of the program need to change and not the rest of the program and how they communicate.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Class diagram sign for public

A

+

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Class diagram sign for private

A

-

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Class diagram sign for protected

A

#

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How a class in a class diagram is set out

A

Name
Attributes
Methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly