Software Development Flashcards
In OOP what is a class
A class is a template for an object and defines the state and behaviour of an object. The state is given by attributes which give an object’s properties. Behaviour is defined by the methods associated with a class, which describe the actions it can perform.
What is instantiation
The process of creating an object in OOP
What is a setter
A setter is a method that sets the value of a particular attribute.
What is a getter
A getter is another special method used in OOP which retrieves the value of a given attribute.
What is the purpose of using getter and setter methods
To make sure attributes cannot be directly accessed and edited by users. This property of object-oriented programming is called encapsulation.
What is a constructor method
A constructor allows a new object to be created, by defining the characteristics of the object
What is inheritance
Where a subclass inherits the attributes and methods of the superclass while having its own
Why is inheritance useful
Allows programmers to effectively reuse certain components and properties while making some changes.
What is meant by polymorphism
Objects can behave differently depending
on their class. This can result in the same method producing different outputs depending on the object involved.
Describe the 2 types of polymorphism
Overriding: redefining a method within a subclass and altering the code so that it
functions differently and produces a different output.
Overloading: passing in different parameters into a method
What is an advantage of polymorphism
Like inheritance, it allows for a high level of reusability, which makes it useful for projects were there are multiple components with similar properties
What is the advantage of encapsulation
Encapsulation is a key reason for choosing OOP as it makes the code more reliable by protecting attributes from being directly accessed. Code for different classes can also be produced independently of others.
Give 2 disadvantages of OOP
2 from:
- This is a different style of programming and so requires an alternative style of
thinking. This can be difficult for programmers accustomed to other paradigms to
pick up.
- OOP is not suited to all types of problems. Where few components are reused,
OOP may in fact result in a longer, more inefficient program.
- Generally unsuitable for smaller problems.