Object Oriented Programming (OOP)

0.0(0)
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/31

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

32 Terms

1
New cards

Object-oriented programming (OOP)

A programming paradigm where the system is viewed as a set of objects, each with their own data (attributes) and procedures (methods), that can interact with each other. All processing is done by objects.

2
New cards

Programming paradigm

An overall approach to writing program code

3
New cards

Object

Partiular instance of a class

4
New cards

Attributes

Values held by an object

5
New cards

Instantiation

The process of making an instance of an object from the class (definition). The object is assigned to a reference variable. Multiple instances of objects can be created. Each must have its own reference variable.

6
New cards

Class (definition)

A template / blueprint for an object and defines the state (the properties of the objects, given by attributes) and behaviour (actions it can perform, given by methods) of an object

7
New cards

UML is the abreviation of ā€¦

ā€¦ abreviation of Unified Modeling Language

8
New cards

Class diagrams

Used to plan what attributes and methods a class will have. Each class is a box with three sections:

  • Name of the class at the top

  • Attributes and their data types in the middle sectionĀ Ā 

  • The methods including parameters and returned data types at the bottom

<p>Used to plan what attributes and methods a class will have. Each class is a box with three sections:</p><ul><li><p>Name of the class at the top</p></li><li><p>Attributes and their data types in the middle section&nbsp;&nbsp;</p></li><li><p>The methods including parameters and returned data types at the bottom</p></li></ul><p></p>
9
New cards

Methods

Actions an object can perform

10
New cards

Constructor

  • Special method that creates an instance of an object from a class

  • It carries out any actions that are needed for this, such as setting the initial values of the attributes

  • ____ have specific names (depends on the language)

11
New cards

Reference variable

  • Holds the address of the location in memory at which the specific object can be found.

  • Whenever an instance of an object is created, it must be assigned to a _______

12
New cards

Access modifiers

Specify which properties (attributes and methods) can be accessed from outside the class. One of:

  • Public

  • Private

  • Protected

13
New cards

Public (attributes or methods)

(Attributes or methods) that can be accessed/called from another part of the program (outside the class). Most methods are _____, but almost all attributes are not.

14
New cards

Private (attributes or methods)

(Attributes or methods) that can not be accessed/called from another part of the program (outside the class). Attributes are almost always ____, whereas most methods tend not to be.

15
New cards

How objects interect with each other

They use 'message passing'; (this just means that) they call each other's public methods.

16
New cards

Encapsulation

  • When attributes are declared as private so can only be accessed and modified by public methods.

  • This hides the data (attributes), making programs less complex by protecting data from being accidentally edited by other parts of the program.

17
New cards

Advantages of encapsulation

  • Reduces the chance of errors/inconsistences

  • Ensures objects can only be changed in the way intended/ Ensuring changes are consistent with how the object should behave

  • Protecting data/ Canā€™t be changed accidentally

18
New cards

Accessors

Special methods that exist to get the value of an attribute. (aka getters)

19
New cards

Mutators

Special methods that exist to set or change the value of an attribute.(aka setters)

20
New cards

Designing classes to be stand-alone allowsā€¦

ā€¦allows class designers to change the implementation details without any adverse effect on the applications that make use of them.

21
New cards

Benefits of making classes self-contained

  • The class can be (re)used in other applications

  • You can change the internal workings of any class, as long as the public interface isn't changed

22
New cards

Inheritance

When a child class / subclass / derived class takes on attributes and methods of a parent class / superclass / base class

23
New cards

Overriding inherited methods

  • Inherited methods can be _____ to change their functionality and make the behaviour more appropriate to the subclass.

  • Is a form of polymorphism.

24
New cards

Protected property

A property that can be directly accessed by a subclass

25
New cards

Extending a subclass

Giving a subclass additional attributes and methods

26
New cards

Polymorphism

Fundamental OOP concept. It is the ability of an object to specialise its behavior based on its type; when a method is called, the code that is executed will depend on the object type. Two examples (you need to know) of how this is achieved is:

  • Method overriding

  • Method overloading

27
New cards

Method overloading

  • Having multiple methods of the same name, but that differ in terms of their parameter list, in a class.

  • When one of these methods is called, the one with the matching parameter list is executed.

  • Is a form of polymorphism.

28
New cards

Method signature

Combination of a method identifier and its parameter list

29
New cards

Advantages of OOP

  • Usually easier for us to think in terms of objects (and their attributes & behavious) than to think procedurally

  • Prewritten classes promote and support code reuse

  • Classes are highly modular, and this means that they are easy to maintain

  • Encapsulation provides a high level of protection for data - ensures that the data can never be modified carelessly and that any associated actions also happen (e.g. when a goal is scored in a game, you can make sure the player's score is incremented)

30
New cards

Disadvantages of OOP

  • OOP design techniques can result in a much larger, more complex system being built in order to achieve a result

  • Potential performance degredation (higher latency and increased resource consumption)

    • OOP relies on message passing for communication between objects

    • Systems with high volumes of message passing can suffer from the overhead involved in message creation, transmission, and processing

    • This can intruduce latency and increase resource consumption

  • Inheritance can have unintended consequences - objects can acquire the ability to do things that don't make sense (e.g. flying pigs)

  • Objects can take up a relatively large amount of memory as they typically require memory allocation for metadata (like pointers to methods and class information) as well as their own attributes.

31
New cards

Inheritence diagram

  • Diagrams that show inheritance relationships

  • Inheritance is shown with open-headed arrows that point up from the child class to the parent class

<ul><li><p>Diagrams that show inheritance relationships</p></li><li><p>Inheritance is shown with open-headed arrows that point up from the child class to the parent class</p></li></ul><p></p>
32
New cards

Purpose of a constructor

To create an instance of an object from a class