Object Oriented Programming (OOP)

5.0(1)
studied byStudied by 10 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/32

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

33 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

  • Each object that is instantiated from the same class will share the same attributes and methods.

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.

  • 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 for an object that defines the attributes and methods an object should have. It is used to make objects.

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 they can only be accessed and modified by public methods.

  • This protects the attributes from being accessed or accidentally altered by other objects

17
New cards

Advantages of encapsulation

  • Protects data - data can’t be changed accidentally

  • Reduces the chance of errors/inconsistences

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

18
New cards

Getters

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

19
New cards

Setters

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

20
New cards

Difference between get and set methods

  • A get method allows the attribute to be accessed / returned 

  • A set method allows the attribute to be changed (with parameters)

21
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.

22
New cards

Benefits of making classes self-contained

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

  • Allows you to change the internal workings of classes, as long as the public interface isn't changed

23
New cards

Inheritance

  • When a child class / sub class takes on the attributes and methods of a parent class / superclass.

  • The child class / sub class can also have its own extra attributes/methods.

24
New cards

Overriding inherited methods

  • When a method name is the same in a parent and sub class, then the method in the parent/super class will be overridden 

  • Is a form of polymorphism.

25
New cards

Protected property

A property that can be directly accessed by a subclass

26
New cards

Extending a subclass

Giving a subclass additional attributes and methods

27
New cards

Polymorphism

  • 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

28
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.

29
New cards

Method signature

Combination of a method identifier and its parameter list

30
New cards

Advantages of OOP (over a procedural paradigm)

  • Code can easily be reused… 

    • …classes can be used in other programs 

    • …inheritance can be to extend upon existing classes 

    • …as a class can be based on an existing class 

  • Easier to maintain…. 

    • ….as classes can be modified or extended 

    • …debugging can be easier as encapsulation limits how attibutes are changed. 

  • Code can be more secure as access to attributes can be restricted to being via methods. 

  • Better for coding as part of a team as classes can be distributed between team members

31
New cards

Disadvantages of OOP

  • OOP design techniques can result in a 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.

32
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>
33
New cards

Purpose of a constructor

To create an instance of an object from a class