topic: object orientation Flashcards

(38 cards)

1
Q

define object orientated programming

A

a programming paradigm based on the concept of ‘objects’ which can contain data and code.
It attempts to group data and informations into structure items known as objects

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

What is an object in OOP

A

a specific instance of a class that contains attributes and methods

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

what is a class

A

a blueprint/ template for creating objects, defining attributes and methods

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

Define polymorphism

A

the ability of different classes to be treated as instances of the same class through a common interface

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

What is abstraction in OOP

A

the concept of hiding complex implementation details while exposing only the necessary parts

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

True or false: method overloading allows multiple methods with the same name in a class.

A

TRUE

methods must differ in the type or number of parameters

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

what does constructor do

A

method that is called when creating an instance of a class

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

what is composition in OOP

A

a design principle where a class is composed of one or more objects from other classes

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

what is the purpose of access modifiers

A

Private and Public, they control the visibility and accessibility of class members
to implement encapsulation (requiring modification through controlled methods like setters and getters),
protect data integrity by preventing direct unauthorized access,
manage code complexity,
and defining the interface for interacting with objects.

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

What is a getter

A

a method that retrieves the value of an object’s attribute

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

Fill in the blank: a setter is used to _______ the value of an attribute

A

set

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

define an abstract class

A

a class that cannot be instantiated and may contain abstract methods

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

what is inheritance

A

when a class hass attributes and methods from its parent class and it can have its own methods and attributes too

it extends a parent class by inheriting its features

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

what does overriding mean in OOP

A

redefining an inherited method (from a parent/ superclass) within a subclass to provide a different implementation

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

What is dependency injection

A

a technique where an object receives its dependencies (object that another class requires to function) from an external source rather than creating them

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

a procedure that starts with “public procedure new (givenName,givenAddress)” is called what

A

a construction

17
Q

benefit of OOP

A

it becomes very easy to reuse the class and create hundreds of objects of that same class

18
Q

what is ‘encapsulation’ in object-oriented programming

A

all of the object’s attributes are contained and hidden in the object by giving them the private access modifier
they are accessed through public getter and setter methods

encapsulation helps in protecting the integrity of the object’s data.

19
Q

define ‘instantiation’

A

creating a specific, usable instance (object) from a class blueprint, using the word ‘new’

This is a fundamental concept in object-oriented programming.

20
Q

what is an ‘attribute’

A

a specific piece of data representing a particular characteristic of an object

attributes are often referred to as properties or fields

21
Q

what is a ‘constructor’

A

a method that is called when an object is created, typically to intialise its attributes
ofen called ‘new’

22
Q

what is an object

A

a specific instance of a class

objects are created based on the structure defined by their class

23
Q

what does OOP stand for
and what is it

A

Object-Oriented Programming
this is a programming paradigm which classifies real-world objects into classes and encapsulates the object’s attributes and behaviors

24
Q

what are methods in a class

A

e.g. getters and setters and other subroutines that define the behavior of the object

methods are functions defined within a class that operate on the object’s attributes

25
what is a class in object-oriented programming
a blueprint used to set or define attributes and methods for an object ## Footnote a class is a template for creating objects of a certain type
26
True or false: a class is an object in itself
FALSE ## Footnote a class is not an object; it is a template used to create objects
27
what is an advantage of OOP regarding classes
easy to reuse a class and create multiple objects of that class ## Footnote this reusability simplifies the process of object creation
28
what sign means a private versus a public access modifier
- -means private - +means public
29
how to write an attribute and an example
name followed by data type e.g. #- name: String ## Footnote **(- there to show its a private access modifier)**
30
for the methods: get, and set what are the two different subroutines we use for them and examples for both of them, getting a name or setting a new name
for getters we use a funtion e.g. public function getName() return name end function for setters we use a procedure e.g. public procedure setName(newName) name = newName end procedure
31
what does the 'getter' method do
retrieves the current values of the private attribute
32
when are object orientated techniques best suited to solve problems
when the problems involve modelling real world enitites with properties and behaviours like in games or GUI. by grouping their data and functionality together
33
what is the difference between attribute and methods
attributes represent the state or characteristic of an object e.g button in GUI has properties of size and colour methods represent the actions the object can perform e.g. character being able to more side to side or update their values
34
In the pseudocode examples, how is a new object of the 'Pet' class with the name "Fido" created?
myPet = new Pet("Fido", "Terrier")
35
what is the advantage of inheritance
promotes code usability as it allows classes to take properties from other pre-existing classes without them being rewritten
36
Write a line of code to create an object of type ItemForSale called mushypeas that has a name of “mushy peas” and a price of £0.89
mushypeas=new ItemForSale("mushy peas", 0.89) ItemForSale mushypeas = ItemForSale(“mushy peas”,0.89); mushypeas=ItemForSale((“mushy peas”,0.89);
37
The discount attribute represents a percentage discount on the price. The discount can be between 0 and 50 (inclusive). All new items for sale initially have a discount value of 0. Write the constructor method for the ItemForSale class.
public procedure new(pItemName, pPrice)    itemname = pItemname    price = pPrice    discount = 0 endprocedure
38
write the pseudocode for a fully encapsulated House class with attributes for square footage and number of rooms include a constructor method write a getter and a setter method for number of rooms
class House private squareFootage private rooms public procedure new (givenSquareFootage, givenRooms) squareFootage = givenSquareFootage rooms = givenRooms end procedure public procedure setRooms(newRooms) rooms = newRooms end procedure public function getRooms() return rooms end function end class