OOP Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Distinguish the difference between a class and an insanitation (3)

A

The class Swimmer is the blueprint of a Swimmer object;
An instantiation is the actual object filled with data;
The class Race stores up to 8 different instantiated objects of the Swimmer class

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

Define the term mutator method (1)

A

A method that allows/controls changes to a private (hidden) variable

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

What is a class?

A

A class is a blueprint or a template for creating objects (instances).
It defines a data structure that includes attributes (often called fields or properties) and methods (functions or procedures) that operate on those attributes.
Think of a class as a user-defined data type that encapsulates data and behavior.
It serves as a blueprint from which objects can be created.

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

What is instantiation?

A

An instance, also known as an object, is a concrete occurrence of a class.
When you instantiate a class, you create a specific object based on that class’s blueprint.
Objects created from the same class have common structure (attributes) and behavior (methods), but they represent distinct entities in the program.
Each instance has its own set of attribute values, independent of other instances.

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

What is aggregation?

A

Aggregation is a concept in object-oriented programming and software design where one class represents a whole and another class represents a part of that whole. It is a form of association that represents a “has-a” relationship between objects. In aggregation, the part (or component) can exist independently of the whole, and it can be associated with multiple instances of the whole.

The main idea behind aggregation is to model relationships between objects in a way that allows for flexibility, reusability, and modularity in software design.

The part (or component) can exist independently of the whole.
When the whole is destroyed, the part can continue to exist.
Multiplicity:

A whole can be associated with multiple instances of the part.
The part can be shared among different wholes.
Flexibility:

Aggregation provides flexibility in constructing complex objects by combining simpler ones.
It allows for the creation of complex structures without tightly coupling the classes involved.
Example:

Consider a university system where a Department class aggregates multiple Professor objects. Each professor can be associated with one department, but they can exist independently of the department.

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

Advantages of aggregation

A

, y:

Aggregation facilitates code reusability by allowing parts of a system to be reused in different contexts. Since the parts can exist independently of the whole, they can be employed in various scenarios, promoting a more modular and reusable codebase.
Flexibility in Design:

Aggregation provides flexibility in designing and evolving systems. Objects can be combined in different ways to create new configurations without the need for major modifications to existing code.
Easy to Understand Relationships:

Aggregation helps represent relationships between objects in a clear and intuitive manner. The “has-a” relationship is often easier to understand than more complex relationships, contributing to better code readability.
Reduced Coupling:

Aggregation helps reduce coupling between classes, as the whole and part objects remain relatively independent. Changes to one part of the system are less likely to impact other parts, promoting a more loosely coupled architecture.
Natural Representation of Real-world Concepts:

Aggregation often aligns well with real-world concepts, making the code more intuitive and reflective of the problem domain. For example, a university system can naturally represent departments aggregating professors.
Supports Object Composition:

Aggregation supports object composition, allowing developers to compose complex objects from simpler ones. This is particularly useful when building systems with a hierarchical or tree-like structure.
Promotes Code Maintenance:

When changes are needed, the modular nature of aggregation makes it easier to maintain and update specific components without affecting the entire system. This can be especially valuable in large software projects.
Dynamic Relationships:

While there can be challenges with dynamic relationships, aggregation can still support dynamic changes to the structure of objects. Parts can be added or removed dynamically, providing some level of adaptability.
Simplified Testing:

Aggregated components can often be tested independently, simplifying the testing process. This isolation of components makes it easier to identify and fix issues within specific parts of the system.

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

Disadvantages of aggregation

A

can cause issues with processing
Complexity:

Aggregation can introduce additional complexity to the design of a system. Managing relationships between whole and part objects, especially when dealing with multiple levels of aggregation, may increase the overall complexity of the code.
Inconsistent Usage:

In some cases, the distinction between aggregation and composition (another form of association) can be subjective. Developers might interpret the relationship differently, leading to inconsistent usage of aggregation, which can impact code clarity and maintainability.
Ownership Ambiguity:

The concept of ownership in aggregation can be ambiguous. It might not always be clear which class is responsible for the lifecycle of the part objects. This ambiguity can lead to issues when it comes to object destruction and resource management.
Dependency:

Aggregation implies a level of dependency between the whole and its parts. Changes in the part class may affect the whole class, and vice versa. This dependency can make the system more rigid and less adaptable to changes.
Navigation Challenges:

Navigating through a complex aggregation hierarchy may become challenging. Traversing from a whole to its parts and vice versa might require intricate code, reducing the overall readability and understandability of the system.
Dynamic Relationships:

Aggregation typically assumes a static relationship between the whole and its parts. If dynamic relationships are required (where parts can be added or removed dynamically), aggregation might not be the most suitable choice.
Performance Overhead:

Depending on the implementation, aggregating objects may introduce some performance overhead, especially if there are frequent queries or manipulations of the aggregated objects.
Potential for Overuse:

In some cases, developers might overuse aggregation when a simpler association or composition would be more appropriate. Overusing aggregation can lead to unnecessary complexity in the code.

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

Describe one feature of modern programming languages that allows the wide range of students names to be represented correctly (3)

A

Modern programming languages use Unicode to encode characters.
Which uses 16 bits / has about 64 000 characters.
As opposed to ASCII which uses 8 bits / has 256 characters.

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

Outline two advantages of the OOP feature ‘inheritance’ (4)

A

t promotes code reuse;
Because the parent object holds common data and action;
It reduces maintenance overhead;
Because you only have to update the parent;

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

What is method overriding

A

Method overriding redefines/replaces a method from the inherited class;
The constructor could only instantiate the finals object;
The method addSwimmers() could fill finals directly;
The method fillFinals() could do nothing;

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

State the implication of using the term static

A

The values are the same for all objects

They belong to the class and not the objects

and are only created/declared once

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

The advantage of using different data types

A

Having different data types allow different operations to be carried out depending on the type

memory usage can be reduced

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

OOP basic find loop

A
  1. public static/void etc functionName(String variable1, String variable2)
  2. (

int x = 0
double variable3 = 0.0;
boolean found = false;
while (!found)
(
if ((variable1[x].getZ()) == c)

(variable3 = variable1[x].getX();
found = true;

)
x++;
)

return variable3;
)

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

Describe two benefits a team would gain from encapsulation

A
  1. encapsulation places all attributes and methods that relate to a particular object/entity together
    a) example relating to context
    b) clearer view or understanding of the problem
    c) leading to more efficient programming
  2. encapsulation protects the values of the data stored within the object
    from accidental changes in other classes
    a) example in given context

b) allows programmers to select any variable names they wish/no restriction on choice of varaible names

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

encapsulation

A

refers to the inclusino of both data and actions into a single component

classes contain data and actions that are built in such a way so that their structure is hidden and can only be accessd outside the class specific via methods

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

Advantages of encapsulation

A
  1. data in a class can be made read or write only
  2. a class restricts the ways that its data and actions can be altered or called
  3. a class can hide the way data is stored
  4. easier to maintain, as changes to data and actions in a class can take place without being apparent on the outside
  5. increase in usability
17
Q

Advantages of inheritance

A
  1. extensability - all child classes inherit and may add new functionality
  2. reusability - when parent classes are upgraded, child classes are upgraded too
  3. information hiding - parent class determines what actions and data are available to child classes
  4. overriding of actions
    - child may override paretns in order to implement meaninful actions for their needs
18
Q

Advantages of polymorphism

A
  1. Object actions can have the same name but different parameter lists and processes
  2. subclasses can have unique actins
  3. subclasses inherit all parent data and actions, alter actions if necessary - reusablity
  4. high degree of decoupling; common interface exists and hides the details of implementation
    (one thing that can take many forms)
    - reduce dependency between components in classes and object systems
19
Q

What are libraries of objects?

A

collection of classes that have already been written in code and can be used while developing a program

20
Q

Advantages of libraries

A

Reuse of chode

instead of writing code from scratch, programmers may use libraries of objects to perform standard functionalities

21
Q

What is modularity

A

dividing a computer program into separate, smaller sub-programs that can be tested on their own before being combined

22
Q

advantages of modularity

A
  1. reuse for same fucntianlity
  2. less new code needs to be re-written
  3. team supoprt
  4. sub programs are easier to maintain and debug
  5. structure of program is easier to understand
  6. completion of sub programs is faster instead of tackling one large problem
23
Q

Association

A

represented in a solind line
simple relationship

24
Q

Dependency

A

Uses relationship

  • dotted line

dependent on one or more object to function

25
Q

Aggregation

A

diamond + line

one object belongs to another object and no other

‘has a” relatinoshi

26
Q

Inheritance

A
27
Q

General nature of an object

A
  1. Abstract entity
  2. and its components are data or actions
28
Q

Disadvantages of OOP

A
  1. Unsuitable for minor projects
    a) OOP increases complexity for little gain
  2. OOP programs are larger than other programs
    a) therefore slower
  3. OOP programs take effort to construct
    a)because of the decompositino needed for abstraction
29
Q

Modularity advantages

A
  1. easier to debug
    a) sub program less likely to have errors
  2. faster development
    a) different teams working on different modules
  3. easier to update in future
    a) easier to update module than full program
  4. re-usablilty
    a) modules can be stored in libraries and ued for differeny programs
30
Q

binary search advantage

A
  1. faster than sequential search
  2. as it halves the search range in every comparison
31
Q

binary search disadvantage

A
  1. not applicable for unsorted sets
  2. data must be applicable first which adds to computational costs
32
Q
A