{ "@context": "https://schema.org", "@type": "Organization", "name": "Brainscape", "url": "https://www.brainscape.com/", "logo": "https://www.brainscape.com/pks/images/cms/public-views/shared/Brainscape-logo-c4e172b280b4616f7fda.svg", "sameAs": [ "https://www.facebook.com/Brainscape", "https://x.com/brainscape", "https://www.linkedin.com/company/brainscape", "https://www.instagram.com/brainscape/", "https://www.tiktok.com/@brainscapeu", "https://www.pinterest.com/brainscape/", "https://www.youtube.com/@BrainscapeNY" ], "contactPoint": { "@type": "ContactPoint", "telephone": "(929) 334-4005", "contactType": "customer service", "availableLanguage": ["English"] }, "founder": { "@type": "Person", "name": "Andrew Cohen" }, "description": "Brainscape’s spaced repetition system is proven to DOUBLE learning results! Find, make, and study flashcards online or in our mobile app. Serious learners only.", "address": { "@type": "PostalAddress", "streetAddress": "159 W 25th St, Ste 517", "addressLocality": "New York", "addressRegion": "NY", "postalCode": "10001", "addressCountry": "USA" } }

OOP and other coding info Flashcards

(24 cards)

1
Q

what is a class

A

A blueprint for creating objects.

It defines a set of attributes (data) and methods (functions) that the objects created from the class will have.

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

what is an object

A

Objects are instances of a class created with specifically defined data

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

examples of classes and objects

A

Class: Car

Attributes: color, model, year
Methods: drive(), brake()
Object: my_car (an instance of Car)

Attributes: color = ‘red’, model = ‘Toyota’, year = 2022
Methods: my_car.drive(), my_car.brake()

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

what is a method

A

a block of code associated with a class or object, defining the behavior and actions an object can perform

  • or simply put, its a function that goes inside a class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is Object-Oriented Programming (OOP)?

A

A programming paradigm based on the concept of objects, which can contain data (attributes) and code (methods).

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

What is a constructor in Python?

A

A special method called __init__() used to initialise an object’s attributes when it is created.

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

What is instantiation?

A

The process of creating an object from a class using the class name and parentheses (e.g. player = Player()).

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

What is encapsulation?

A

The concept of hiding the internal state of an object and only allowing access through public methods.

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

What is a private attribute in Python?

A

An attribute prefixed with double underscores (e.g. __score) to signal it should not be accessed directly from outside the class.

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

: What is inheritance?

A

A mechanism where a child class inherits the attributes and methods of a parent class, allowing for reuse and extension.

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

What is super() used for?

A

To call methods from the parent class, typically used in a child class’s constructor.

refers to the class we have inherited from

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

What is polymorphism?

A

The ability for different classes to have methods with the same name but potentially different behaviours.

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

What is method overriding?

A

When a child class provides a new version of a method that is already defined in the parent class.

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

What is a getter and setter?

A

Methods used to access (get) and update (set) the value of a private attribute.

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

how does a class attribute differ from a regular attribute

A

an attribute that doesnt use self, not specific to any instance

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

difference between variables and constants

advantages of named constants

A

A variable is a storage location in memory that can hold a value, and the value can change during the program’s execution.

A constant is also a storage location, but its value is fixed and cannot be changed after initialization.

Advantages of using named constants:

Readability:
Constants are given meaningful names, making the code easier to understand.

Maintainability:
If the value of a constant needs to be changed, it only needs to be modified in one place, not throughout the code where the literal value is used.

Code clarity:
Constants help separate data values from the logic of the program, improving code clarity.

Efficiency:
Using named constants can sometimes improve performance, especially when dealing with complex operations.

16
Q

describe the function of parameters

A

used to pass data between different parts of a program, like functions or subroutines, allowing them to share and manipulate values.

This avoids the need for global variables, reducing the risk of unintended side effects and making code more organized.

17
Q

local vs global variables

A

local variables are defined within a function or block of code and are only accessible from within that scope

. Global variables, on the other hand, are declared outside any function and are accessible throughout the entire program

18
Q

Advantages of the structured approach / using hierarchy charts

A

Advantage Explanation
Modular design Each module is small and manageable.
Easier to test/debug Can test individual modules independently.
Reusability Modules can be reused in other programs.
Improved readability Clear top-down flow of logic.
Teamwork-friendly Developers can work on different modules in parallel.
Reduced complexity Breaking down a large problem makes the system easier to understand and maintain.

19
Q

Instantiation

A

The process of creating an object from a class.

20
Q

Encapsulation

A

Hiding internal data of an object and only allowing access through public methods.

21
Q

Aggregation

A

A “has-a” relationship: one object uses another, but they can exist independently. UML: ⚪ (white diamond).

22
Q

Overriding

A

When a subclass provides a new version of a method defined in the parent class.

23
Q

Why Use OOP?

A

Easier modularity: break the system into manageable pieces.

Encourages code reuse through inheritance and composition.

Facilitates maintenance and updates.

Allows real-world modelling using objects.