oop terms need2know Flashcards
class, object (and the difference between the two)
An object is a member or an “instance” of a class. An object has a state in which all of its properties have values that you either explicitly define or that are defined by default settings. This subtle conceptual difference between classes and objects shows why there is a tendency to want to use them interchangeably.
instantiation
Instantiation is the use of object classes. (An object class is a set of objects that share a common structure and a common behaviour). Instantiation is fundamentally a word for the use of inheritance. Programmers can define object classes, define their own kinds of objects, and instantiate them as needed.
method (as opposed to, say, a C function)
A function is a piece of code that is called by name. It can be passed data to operate on (i.e. the parameters) and can optionally return data (the return value). All data that is passed to a function is explicitly passed.
A method is a piece of code that is called by a name that is associated with an object. In most respects it is identical to a function except for two key differences:
A method is implicitly passed the object on which it was called. A method is able to operate on data that is contained within the class (remembering that an object is an instance of a class - the class is the definition, the object is an instance of that data).
virtual method, pure virtual method
A virtual method is a method that CAN be overridden in derived classes from the class that DEFINES it. A pure virtual method is a method that MUST be overridden in derived classes from the abstract class that DECLARES it. In C# and Java jargon it is called an “abstract method”.
class/static method
Essentially, static methods let you write procedural code in an object oriented language. It lets you call methods without having to create an object first. … Static variables and static methods are bound to the class, and not an instance of the class. Static methods should not contain a “state”.
static/class initializer
If you also remove static from the initializer block, it then becomes an instance initializer and so int a is initialized at construction. The static initializer is a static {} block of code inside java class, and run only one time before the constructor or main method is called.
constructor
Constructor (object-oriented programming) In class-based object-oriented programming, a constructor (abbreviation: ctor) is a special type of subroutine called to create an object. It prepares the new object for use, often accepting arguments that the constructor uses to set required member variables.
destructor/finalizer
In object-oriented programming, a finalizer or finalize method is a special method that performs finalization, generally some form of cleanup. A finalizer is executed during object destruction, prior to the object being deallocated, and is complementary to an initializer, which is executed during object creation, following allocation. Finalizers are strongly discouraged by some, due to difficulty in proper use and the complexity they add, and alternatives are suggested instead, primarily the dispose pattern[1] – see problems with finalizers.
superclass or base class
The class from which the subclass is derived is called a superclass (also a base class or a parent class). Excepting Object , which has no superclass, every class has one and only one direct superclass (single inheritance). … A subclass inherits all the members (fields, methods, and nested classes) from its superclass.
subclass or derived class
The derived class (the class that is derived from another class) is called a subclass. … The subclass inherits state and behavior in the form of variables and methods from its superclass. The subclass can use just the items inherited from its superclass as is, or the subclass can modify or override it.
inheritance
Inheritance. In object-oriented programming, inheritance enables new objects to take on the properties of existing objects. A class that is used as the basis for inheritance is called a superclass or base class. A class that inherits from a superclass is called a subclass or derived class.
encapsulation
Encapsulation is one of the fundamental concepts in object-oriented programming (OOP). It describes the idea of bundling data and methods that work on that data within one unit, e.g., a class in Java. This concept is also often used to hide the internal representation, or state, of an object from the outside.
multiple inheritance (and give an example)
Multiple inheritance is a feature of some object-oriented computer programming languages in which an object or class can inherit characteristics and features from more than one parent object or parent class. It is distinct from single inheritance, where an object or class may only inherit from one particular object or class.
delegation/forwarding
In object-oriented programming, forwarding means that using a member of an object (either a property or a method) results in actually using the corresponding member of a different object: the use is forwarded to another object. Forwarding is used in a number of design patterns, where some members are forwarded to another object, while others are handled by the directly used object. The forwarding object is frequently called a wrapper object, and explicit forwarding members are called wrapper functions.
Forwarding is often confused with delegation; formally, they are complementary concepts. In both cases, there are two objects, and the first (sending, wrapper) object uses the second (receiving, wrappee) object, for example to call a method.
composition/aggregation
Aggregation implies a relationship where the child can exist independently of the parent. Example: Class (parent) and Student (child). Delete the Class and the Students still exist. Composition implies a relationship where the child cannot exist independent of the parent.