Explain basic object-oriented concepts Flashcards
Class and object
Class
A blueprint that defines the variables and the methods common to all objects of a certain kind.
Object
An instance of a specific class. Simply a self-contained component which consists of methods and properties to make a particular type of data useful.
Interface inheritance
When a class implements an interface, it and its subclasses inherit the methods within the interface.
Variables and attributes
Variables
Containers for storing datavalues (int, string, boolean, etc).
Attributes
Metadata of a program’s object(s), whilst a variable is a program object.
Abstract classes and interfaces
Abstract classes A class which cannot be instantiated, but can be subclasses. Defines the base-behavior of subclasses (objects).
Interfaces A completely "abstract class" that is used to group related methods with empty bodies. All methods defined by an interface must appear in a class which implements said interface.
Static and dynamic types
Static types
That which is defined and instantiated during compilation. Will always be the same when the code is run - unchangeable!
Dynamic types
Data decided at run-time execution (runtime polymorphism).
Dynamic binding
A choice between several different possible implementations of a polymorphic method (i.e an overridden method), decided at run-time.
Primitive types and reference types
Primitive types The following data types are primitive: • boolean • byte • short • char • int • long • float • double
Reference types
Reference types hold references to objects, and provide a means to access those objects stored somewhere in memory. These include Integers (not ints!!), Arrays (called array-types), or classes/interfaces (class-types).
Overloading and overriding
Overloading When two or more methods in the same class have the same name. Typically have the same responsibility.
Overriding When a subclass overrides a method created in a superclass (using @override and the same name). Used when the implementation of a certain behaviour/algorithm must be determined dynamically, stemming from the objects handling the behaviour differently. Method is polymorphic.
Encapsulation
Encapsulation refers to the bundling of fields and methods inside a single class. Used to implement an information-hiding mechanism. One must declare class variables/attributes as private, and provide public get and set methods to access and update the value of a private variable.
Aliasing
Aliasing means that more than one reference is tied to the same object.