Object oriented programming 1 Flashcards

1
Q

What are attributes?

A

Attributes are specific properties of an object.

"Matz".length
# ==> 4
Matz is an object
.lenght is a method
4 is an attribute
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a class?

A

A class is a way to organize and produce objects with similar attributes and methods.

Basically a blueprint.

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

How do you write a class?

A
class ClassName
   # some code
end

You use CamelCase for the class name

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

What is the initialize method?

A

The initialize method is used to boost up the class, it gives us attributes that we can start up with.
It will run every time we create the class.

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

What is an instance variable?

A

An instance variable makes the variable available in other parts of the application

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

What is scope of a variable?

A

The scope of a variable is where the variable is accessible for the rest of the program. Some variables are not accessible to other parts of the program.

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

What are global variables?

A

Variables that are available everywhere

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

What are local variables?

A

Variables that are only available inside certain methods.

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

How do you write instance variables?

A

you write them with a @

@variable_name

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

How do you write class variables?

A

You write them with two @@

@@variable_nameHow do yo wr

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

How do you write global variables?

A

1) You just define the variable outside the method or class.

2) If you are writing the global variable from inside a method or a class just write $ before the variable.

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

How should you create variables?

A

You should only create them with a limited scope so that they can only be changed from a few places.

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

What is inheritance?

A

inheritance is the process by which one class takes on the attributes and methods of another.

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

What is the inheritance syntax?

A

you use the < symbol to show the inheritance.

class DerivedClass < BaseClass
  # Some stuff!
end

This means that DerivedClass inherits from BaseClass.

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

What is override?

A

If you want a class to not to take the attributes of the baseclass

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

What is the super keyword?

A

The super keyword is used when you want to accesses the attributes or the methods of a superclass

17
Q

How do you set up a class in ruby?

A
class SomeName
end
18
Q

What is inheritance?

A

Inheritance means that a class has access to all methods and behaviors of another class. You use the < to show the inheritance.

19
Q

What can you store in a class in ruby?

A

You can store both methods and data in a class.

20
Q

What is the getter method in a class?

A

The getter method allows you to retrieve data or values from a class.

21
Q

What is the setter method in a class?

A

The setter method allows you to set values in a class.

22
Q

What is the attr_accessor?

A

The attr_accsessor stands for attribute accessor and is used instead of the getter and setter methods.

23
Q

What does instantiation mean?

A

When you create a class it’s like creating a blueprint, to instantiate a class means to build the house from a blueprint. To actually use the class to create.

24
Q

What is an initializer method?

A

An initializer method is a method that will run every time you create a new instance of a class.

25
Q

What are optional values?

A

When you are not sure that you want to pass on a value as an argument, you can assign the value to be optional. It will only be assigned if you give an argument.

You write value = something if you want it to be optional

26
Q

Why do we use inheritance in ruby?

A

We use inheritance because repeating code is a bad practice.

27
Q

What is service-based architecture?

A

It is when you use third party services instead of creating your own.

28
Q

What is a public method?

A
A public method is a method inside a class that can be used by anyone working with that perticular class. 
These are really important if you are giving access to these methods via an API.
29
Q

What are private methods?

A

Private methods are methods that can only be called from whitin the class and not by an external service or user.

30
Q

How do you make a method private?

A

You add the keyword private to a section of your class, and all methods that are added below that keyword will be private.

Ex
class Example

def method_1
some_code
end

private

def method_2
some_code
end

end

31
Q

What is polymorphism in ruby?

A

Polymorphism is when the behavior from the parent class is overridden by the child class.

32
Q

How do you use Polymorphism?

A

You use it by defining a new class with the same method name, the method of the child class will be run instead of the method from the parent class.

33
Q

What is the super keyword and when do you use it?

A

The super keyword allows us to use both methods from parent and child classes instead of polymorphism.

You use it by adding the keyword inside the method you want the parent class to override

34
Q

What is the single responsibility principle?

A

It means that each class and module in the application should only focus on a single task.