Object oriented programming Flashcards
Define class
The definition of the attributes and methods of a group of similar objects
Define attributes
The properties that an object if that type has, implemented using variables
Define methods
Processes or actions that an object of that type can do, implemented with subroutines
Define object
A specific instance of a class
Define instantiation
The process of creating an object based in its class definition
What is a constructor
A special method that is called when the object is instantiated
What is the relationship between an object and its class?
An object is an instance of the class
What is encapsulation?
The concept of grouping similar attributes, data and methods together in one object
What is information hiding?
Controlling access to other data stored within an object
State the name, symbol and meaning for the three main access specifiers
- Private: Cannot be accessed from any other object
+ Public: Can be accessed from any object
# Protected: Can only be accessed from this object or an object of this class/ subclass
What is grouped together in encapsulation?
Attributes
Methods
Data
What are the advantages of encapsulation?
Makes program more modular
Makes debugging easier
Allows programming tasks to be split between different programmers
Prevents access to certain attributes or methods from other objects
How is it possible for private attributes to be accessed by other objects?
Getters and setters which are public methods that can access private attributes
What is inheritance?
The idea that a class can use the attributes and methods defined in another class
What is a subclass?
A class that inherits the attributes and methods from another class
What is a base/parent class?
A class whose attributes and methods are inherited by another class
What are the benefits of inheritance?
Same code can be reused without the need to copy it
If code needs changing it only needs to be changed in the base class
Less chance of errors
Easier to debug
What is aggregation?
The idea that one class can be related to another using a ‘has a’ relationship
What is a container class?
A class or object that contains or is made up of other objects
Describe the two types of aggregation
Association aggregation: Aggregation where the container object can be destroyed without destroying it’s associated objects
Inheritance aggregation: Aggregation where, if the container object is destroyed then all associated objects are destroyed
What is an associated class/object?
A class/object that is used to make up another object
What is the difference between inheritance and aggregation?
Inheritance is an ‘is a’ relationship, aggregation is a has a relationship
Define polymorphism
The ability for two methods with the same name to carry out their actions using different code
Define overriding
A method in a subclass re-defining a method inherited from a bass class
How can a computer identify which method to run if there are two methods with identical identifiers in that class?
Comparing the number and type of the arguments
against the expected parameters of each method
What is an interface?
A collection of subroutines that can be implemented by unrelated classes
What are the advantages of using OOP?
OOP more closely resembles the real world relationships between objects
Easier to debug
Classes can be reused in other code
Code can be reused through inheritance and aggregation
What are abstract methods?
A method that has no program code and is intended to be overwritten
What are virtual methods?
Methods that may be overwritten (default in some languages)
What are static methods?
Methods in a class that can be called without the need to create an object of that class
What should be included in a detailed class diagram?
Class names Attributes Methods Data types Access specifiers Relationships