Module definitions Flashcards

1
Q

What is an OO language

A

A language which promotes or allows object oriented programming and design

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

What is an object?

A

A collection of data

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

What is a class?

A

Defines what an object can do

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

What is a class method?

A

A static method which is associated with a class

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

What is an instance method?

A

A non-static method which is associated with an object

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

What is aggregation?

A

An object within an object where the inner object has a lifetime of its own

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

What is the symbol for aggregation in a class diagram?

A

An empty diamond

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

What is composition?

A

An object within object where the inner object lasts as long as the outer object

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

What is the symbol for composition in class diagram?

A

A black filled in diamond

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

What is abstraction?

A

Hides the implementation from the user for simplicity

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

What is an abstract method?

A

A method without implementation (no {}) - these are placeholders for sub-classes to implement/override

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

What is an abstract class?

A

A class with at least one abstract method- CANNOT create instances of the class (only references)

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

What is an interface?

A

A class where every method is abstract and any data is static and final. (a class with no implementation)

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

What is inheritance?

A

A class is as specialisation of another class

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

What is the symbol for inheritance in a class diagram?

A

A white arrow

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

How does inheritance work with classes?

A

A class extends a class

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

How does inheritance work with a class and an interfaces?

A

A class implements an interface

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

How does inheritance work with interfaces?

A

An interface extends an interface

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

How does inheritance work with interfaces and classes?

A

DOESNT WORK THIS WAY -> a class can implement an interface not the other way round

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

What is parametric polymorphism?

A

Code which works with multiple different types

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

What is type erasure?

A

Type exists only at compile time and are erased before runtime

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

What is ad-hoc polymorphism

A

Function overloading -> same function name but multiple different versions depending on the parameter types

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

What is sub-type polymorphism?

A

Sub-classing (polymorphism in OO terms)

24
Q

What is runtime polymorphism?

A

Compiler does not know the type but looks it up at runtime

25
Q

What does it mean if a variable is final?

A

It is unchangeable (cant be changed in any implementations or extensions, both methods and classes can be final -can’t change implementation or can’t subclass)

26
Q

What is a design pattern?

A

A reusable solution to commonly faced problems

27
Q

What is a model-view-controller?

A

Separates data storage, presentation to user and control logic

28
Q

What is a behavioural pattern?

A

Patterns that change the behaviour of an object

29
Q

What is a strategy pattern?

A

Lets another object modify the behaviour of an object

30
Q

What is an example of a strategy pattern?

A

Layout manager

31
Q

What is an observer pattern?

A

Tell me when something happens

32
Q

What is an example of an observer pattern?

A

Button

33
Q

What is an iterative pattern?

A

Lets you iterate through contents

34
Q

What is an example of an iterative pattern?

A

For each loop! Mainclass implements class iterable, now we can have a myIterator class which implements iterator

35
Q

What is an iterable?

A

A container to iterate through

36
Q

What is an iterator?

A

Object to do the iteration

37
Q

What is a creational pattern?

A

Pattern related to the creation of objects

37
Q

What is a singleton?

A

Creates just one instance of an object and use it anywhere

38
Q

What is an example of a singleton

A

To create a constant object

39
Q

What is a simple factory?

A

Creates lots of instances of object

40
Q

What is boxing?

A

Wrapping up a data type in an object

41
Q

What is unboxing?

A

Extracting the data type again after boxing it up

42
Q

What is auto-boxing?

A

The process of wrapping a data type in an object then extracting the data type again

43
Q

What is an anonymous class?

A

An inner class without a name

44
Q

What is a lambda?

A

A simpler case for an anonymous class. When an inner class without a name implements an interface with one method

45
Q

What is a constructor?

A

Methods which are called to initialise new objects -> same name as the class like public main()

46
Q

What is encapsulation?

A

Grouping together methods and data in a class

47
Q

Who can view a public method?

A

Anyone

48
Q

Who can view a protected method?

A

Anything in this package and subclasses

49
Q

Who can view a package method?

A

Anything in this package

50
Q

Who can view a private method?

A

Only this class can access it

51
Q

What are the limitations of parametric polymorphism?

A
  • Type erasure
  • Can only parametrise on a sub-class of a specific type
52
Q

How do we change something from type a to a generic type?

A
  • Replace all of the data type with OBJECT
  • Except when we are having a parameter of type T
  • If a method returns a type T, type cast it before returning
53
Q

What are the two types of pattern we have?

A
  • Behavioural patterns
  • Creational patterns
54
Q

Give examples of behavioural patterns

A

Observer, Strategy and Iterator

55
Q

Give examples of creational strategy patterns

A

Singleton and simple factory

56
Q

Why are design patterns useful in general?

A
  • Simplify coding process
  • Enhance code maintainability
  • Promote code reuse