Section 12 - Object-Orientated Programming - USE NOTES Flashcards

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

What is a procedural language?

A

A program consisting of:
- Step-by-step instructions
- Function and procedure calls
- Local and global variables

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

How does procedural programming work?

A

Code is broken down into a number of smaller modules, with the program consisting of a series of calls to procedures and functions, each of which may in turn call other procedures or functions

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

How does object orientated programming work?

A

The world is viewed as a system of objects, each of which is responsible for its own data and the operations on that data. All processing carried out is done by the objects

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

What are attributes?

A

Data that is associated with the class

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

What features do objects have?

A
  • Attributes
  • State
  • Behaviours
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are states?

A

The value of an objects instance variables

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

What are behaviours?

A

Actions that can be performed by an object

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

What is a class?

A

A blueprint or template for an object that defines the attributes and behaviours of those objects

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

What is a method?

A

Attributes and behaviours of an object, they are the functionality of a class

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

What is a constructor?

A

Something used to create objects in a class

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

What are setter methods?

A

Procedures

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

What are getter methods?

A

Functions

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

What is instantiation?

A

Where a new object (an instance of a class) is created

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

Can multiple instances of the same class be created?

A

Yes, they will share identical methods and attributes, however the value of their attributes will be unique to each instance

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

What is a reference type variable?

A

Variables that hold a pointer or reference to where the object itself is stored

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

What is a variable reference diagram?

A

A graphical form showing how objects are referenced by reference variables

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

What is an instance of a class?

A

Objects created from that class

18
Q

What is encapusaltion?

A

All the data and methods of an object are combined into a single entity so that the attributes or behaviours of one object cannot affect the way in which another object functions

19
Q

What is a subclass?

A

A “child” class in object-orientated programming

19
Q

Why do programmers use encapsulation?

A
  • Different programmers can work on different classes and not have to worry about how other parts of the system may affect any code they write
  • They can use methods from other classes without having to know how they work
20
Q

How can you determine whether to use inheritance?

A

Use the “is a” rule. Ask “is object A an object B?”, and if it is then object A should inherit the data and behaviours from object B

21
Q

What is a superclass?

A

A “parent” class in object-orientated programming

21
Q

What is an inheritance diagram?

A

A diagram showing the inheritance relationship between different classes

21
Q

What is inheritance?

A

Child classes inherit data and behaviours from their parent class

22
Q

What is association?

A

A “has a” relationship between classes, meaning there is no ownership between objects and they can be created and deleted independently

23
Q

What is aggregation?

A

A more specific interpretation where a class is a collection or container of other classes, however they do not have a lifecycle dependency

24
Q

What is composition?

A

A stronger form of association, where if the container object is destroyed then every instance of the contained class is also destroyed

25
Q

How is aggregation shown in class diagrams?

A

A hollow diamond shape next to the container object

26
Q

How is composition shown in class diagrams?

A

A filled in diamond shape next to the container object

27
Q

What is polymorphism?

A

A programming languages ability to process objects differently depending on their class.

28
Q

What is overriding?

A

Defining a method with the same name and formal argument types as a method inherited from a superclass

29
Q

Why is composition favoured over inheritence?

A
  • It allows for greater flexibility as composition is a less rigid relationship between the 2 objects
  • An object may be composed of several other objects but cannot be said in a real-world sense to “inherit” their characteristics
30
Q

What is information hiding?

A

Where the objects instance variables are hidden so other objects must use messages to interact with that object’s state

31
Q

What are the 3 access modifiers?

A
  • Public
  • Private
  • Protected
32
Q

What can access a method/instance variable that has been declared public?

A

Code within any class

33
Q

What can access a method/instance variable that has been declared private?

A

Code within the class itself can access it

34
Q

What can access a method/instance variable that has been declared protected?

A

The definition varies between languages, however the most common definitions are only members of the same subclass, and only members in the same package/library of classes

35
Q

What is an interface?

A

A collection of abstract methods that a group of unrelated classes may implement

36
Q

What is the advantage of using an interface?

A

New classes can be added which use the interface without affecting existing classes

37
Q

What is the point of encapsulating what varies?

A

It reduces maintenance and testing effort

38
Q

What is encapsulating what varies?

A

When something changes in a program, if the concept in question is encapsulated in a single module then only that module needs to change

39
Q

What are the advantages of OOP?

A
  • The object-orientated methodology forces programmers to go through extensive planning, making better designs with less weaknesses
  • Encapsulation means that source code for an object can be written, tested and maintained independently of the code for other objects
  • Once an object is created, knowledge of how its methods are implemented is no necessary for it to be used
  • New objects with small differences to existing ones can be created easily
  • Objects that are already defined, coded and tested can be reused in other programs
  • An object-orientated program is much easier to maintain because of its modular structure