oop terms need2know Flashcards

1
Q

class, object (and the difference between the two)

A

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.

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

instantiation

A

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.

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

method (as opposed to, say, a C function)

A

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).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

virtual method, pure virtual method

A

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”.

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

class/static method

A

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”.

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

static/class initializer

A

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.

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

constructor

A

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.

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

destructor/finalizer

A

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.

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

superclass or base class

A

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.

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

subclass or derived class

A

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.

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

inheritance

A

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.

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

encapsulation

A

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.

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

multiple inheritance (and give an example)

A

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.

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

delegation/forwarding

A

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.

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

composition/aggregation

A

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.

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

abstract class

A

abstract class. … Abstract classes are used in all object-oriented programming (OOP) languages, including Java (see Java abstract class), C++, C# and VB.NET. Objects or classes may be abstracted, which means that they are summarized into characteristics that are relevant to the current program’s operation.

17
Q

interface/protocol (and different from abstract class)

A

Protocol is a term used by particular object-oriented programming languages with a variety of specific meanings, which other languages may term interface or trait (or even Dynamic dispatch or Dependency injection), and often associated with languages from Apple Inc.

18
Q

method overriding

A

Method overriding, in object-oriented programming, is a language feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its superclasses or parent classes.

19
Q

method overloading (and difference from overriding)

A

A major topic in OOP is overloading methods, which lets you define the same method multiple times so that you can call them with different argument lists (a method’s argument list is called its signature). C# not only supports method overloading, but revels in it.

20
Q

polymorphism (without resorting to examples)

A
Polymorphism is the ability of an object to take on many forms.
Any Java object that can pass more than one IS-A test is considered to be polymorphic— tutorialspoint. This means any child class object can take any form of a class in its parent hierarchy and of course itself as well. What this actually means is that the child class object can be assigned to any class reference in its parent hierarchy and of course itself as well.
21
Q

is-a versus has-a relationships (with examples)

A

IS-A Relationship:

In object-oriented programming, the concept of IS-A is a totally based on Inheritance, which can be of two types Class Inheritance or Interface Inheritance. It is just like saying “A is a B type of thing”. For example, Apple is a Fruit, Car is a Vehicle etc. Inheritance is uni-directional. For example, House is a Building. But Building is not a House.

HAS-A Relationship:

Composition(HAS-A) simply mean the use of instance variables that are references to other objects. For example Maruti has Engine, or House has Bathroom.

22
Q

method signatures (what’s included in one)

A

It is just the list of arguments expected by a method, and their types. Imagine that objects of type Person have a method called “eat_food”. This might take two arguments, an integer called “quantity”, and a string “foodtype”. That’s the signature.

23
Q

method visibility :public

A

Public

All member variables and methods are public by default in Python. So when you want to make your member public, you just do nothing. See the example below:

24
Q

method visibility : private

A

Private

By declaring your data member private you mean, that nobody should be able to access it from outside the class, i.e. strong you can’t touch this policy. Python supports a technique called name mangling. This feature turns every member name prefixed with at least two underscores and suffixed with at most one underscore into _ . So how to make your member private? Let’s have a look at the example below:

25
Q

method visibility : protected

A

Protected

Protected member is (in C++ and Java) accessible only from within the class and it’s subclasses. How to accomplish this in Python? The answer is – by convention. By prefixing the name of your member with a single underscore, you’re telling others “don’t touch this, unless you’re a subclass”. See the example below: