OOP Flashcards

1
Q

Namespace

A

A container which lets developers bundle all functionality under a unique, application-specific name.

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

Class

A

Defines the object’s characteristics. A class is a template definition of an object’s properties and methods.

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

Object

A

An instance of a class.

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

Property

A

An object characteristic, such as color.

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

Method

A

An object capability, such as walk. It is a subroutine or function associated with a class.

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

Constructor

A

A method called at the moment an object is instantiated. It usually has the same name as the class containing it.

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

Inheritance

A

A class can inherit characteristics from another class.

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

Encapsulation

A

Encapsulation is the packing of data and functions into one component (for example, a class) and then controlling access to that component to make a “blackbox” out of the object. Because of this, a user of that class only needs to know its interface (that is, the data and functions exposed outside the class), not the hidden implementation.

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

Abstraction

A

The conjunction of an object’s complex inheritance, methods, and properties must adequately reflect a reality model.

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

Polymorphism

A

Poly means “many” and morphism means “forms”. Different classes might define the same method or property.

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

Polymorphisme

A

L’idée d’autoriser le même code à être utilisé avec différents types, ce qui permet des implémentations plus abstraites et générales.

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

Public

A

Les variables, méthodes ou classes publiques sont accessibles par tout objet.

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

“Rien” (devant une variable, méthode, classe publique)

A

Les variables, méthodes ou classes définies sans modificateur sont accessibles par toute classe appartenant au même package.

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

Protected

A

Les variables, méthodes ou classes définies comme protégées ne sont accessibles que par les classes filles et classes du même package.

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

Private

A

Les variables, méthodes ou classes définies comme privées ne sont accessibles que par la classe dans laquelle elles sont définies.

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

Static

A

Devant une variable ou méthode : Le mot clé static devant une variable (ou méthode) indique que celle-ci n’appartient pas à une instance particulière de la classe. Les variables ou méthodes statiques appartiennent à la classe elle-même. On peux ainsi les utiliser sans avoir une instance créée. De nombreuses classes ont des membres ou méthodes statiques. Devant un bloc de code : Le mot-clé static devant un bloc de code indique que celui-ci ne sera exécuté qu’une fois.

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

Final (devant une méthode)

A

On indique que cette méthode ne pourra plus être redéfinie dans une classe fille. Ce qui entraîne une certaine optimisation dans les appels à cette méthode.

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

Final (devant une classe)

A

On ne peut pas créer de classe dérivée de celle-ci. Par exemple il est impossible de dériver une classe à partir de la classe String de la bibliothèque de base. La solution consisterait à “encapsuler” String dans une classe de notre conception. Devant une variable membre ou une variable locale : La variable ne peut plus être modifiée après son initialisation, et doit obligatoirement être initialisée une fois (et une seule fois)

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

This

A

Référence à l’instance courante

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

Super

A

Référence à la classe mère

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

Why use getters and setters?

A
  1. When you realize you need to do more than just set and get the value, you don’t have to change every file in the codebase.
  2. You can perform validation here.
  3. You can change the value being set.
  4. You can hide the internal representation. getAddress() could actually be getting several fields for you.
  5. You’ve insulated your public interface from changes under the sheets.
  6. Some libraries expect this. Reflection, serialization, mock objects.
  7. Inheriting this class, you can override default functionality.
  8. You can have different access levels for getter and setter.
  9. Lazy loading.
  10. People can easily tell you didn’t use Python.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Abstract class

A

Abstract classes are distinguished by the fact that you may not directly construct objects from them using the new operator. An abstract class may have zero or more abstract methods.

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

Abstract method

A

An abstract method has no method body. Methods defined in an interface are always abstract. The body of an abstract method must be defined in a sub class of an abstract class, or the body of a class implementing an interface.

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

API

A

A set of definitions that you can make use of in writing programs. In the context of Java, these are the packages, classes, and interfaces that can be used to build complex applications without having to create everything from scratch.

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

Block

A

Statements and declarations enclosed between a matching pair of curly brackets ({ and }). For instance, a class body is a block, as is a method body. A block encloses a nested scope level (not in ES5)

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

Class inheritance

A

When a super class is extended by a sub class, a class inheritance relationship exists between them. The sub class inherits the methods and attributes of its super class. In Java, class inheritance is single inheritance. See interface inheritance for an alternative form of inheritance.

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

Class method

A

A synonym for static method.

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

Class variable

A

A synonym for static variable.

29
Q

Cohesion

A

The extent to which a component performs a single well-defined task. A strongly cohesive method, for instance, will perform a single task, such as adding an item to a data structure, or sorting some data, whereas a weakly cohesive method will be responsible for several disparate tasks. Weakly cohesive components should, in general, be split into separate more cohesive components. The java.util package is a weakly cohesive package because it contains many unrelated classes and interfaces, whereas the java.io package is highly cohesive.

30
Q

Compilation

A

The process of translating a programming language. This often involves translating a high level programming language into a low level programming language, or the binary form of a particular instruction set. The translation is performed by a program called a compiler. A Java compiler translates programs into bytecodes.

31
Q

Compiler

A

A program which performs a process of compilation on a program written in a high level programming language

32
Q

Coupling

A

Coupling arises when classes are aware of each of other because their instances must interact. Linkage between two classes that may be either strong or weak. Stronger coupling arises when one class has a detailed knowledge of the internal implementation of another, and is written to take advantage of that knowledge. So anything that has the potential to reduce the amount of inside knowledge will tend to weaken coupling. Hence, information hiding and encapsulation. Java’s visibility levels - private, package, protected, public - progressively reveal detail to other classes, and so increase the potential for stronger coupling. Interfaces are one way to reduce to reduce coupling - because you interact with a class via an abstract definition, rather than a concrete implementation.

33
Q

Deep copy

A

A copy of an object in which copies of all the object’s sub-components are also made. The resulting object might, in effect, be a clone of the original. See shallow copy for an alternative.

34
Q

Delegation

A

The process by which an object passes on a message it has received to a sub-ordinate object. If inheritance is not available in a programming language, delegation is the most viable alternative for avoiding code duplication and promoting code reuse.

35
Q

Encapsulation

A

Safeguarding the state of an objects by defining its attributes as private and channeling access to them through accessor and mutator methods.

36
Q

Immutable object

A

An object whose state may not be changed. Objects of the String class are immutable, for instance - their length and contents are fixed once created.

37
Q

Import statement

A

A statement that makes the names of one or more classes or interfaces available in a different package from the one in which they are defined. Import statements follow any package declaration {package!declaration}, and precede any class or interface definitions.

38
Q

Instantiation

A

The creation of an instance of a class - that is, an object.

39
Q

Interface inheritance

A

When a class implements an interface, an interface inheritance relationship exists between them. The class inherits no implementation from the interface, only method signatures and static variables. It is also possible for one interface to extend one or more interfaces. In Java, interface inheritance is the only form of multiple inheritance. See class inheritance for an alternative form of inheritance.

40
Q

Local variable

A

A variable defined inside a method body.

41
Q

Member

A

The members of a class are fields, methods and nested classes.

42
Q

Method

A

The part of a class definition that implements some of the behavior of objects of the class. The body of the method contains declarations of local variables and statements to implement the behavior. A method receives input via its arguments, if any, and may return a result if it has not been declared as void.

43
Q

Method body

A

The body of a method: everything inside the outermost block of a method.

44
Q

Method header

A

The header of a method, consisting of the method name, its result type, formal arguments and any exceptions thrown. Also known as a method signature.

45
Q

Method signature

A

A synonym for method header.

46
Q

Method variable

A

See local variable.

47
Q

Namespace

A

The area of a program in which particular identifiers are visible. Java uses packages to provide namespaces, and its visibility rules - private, package, protected, public - variously contain identifiers within namespaces.

48
Q

new operator

A

The operator used to create instances {instance} of a class.

49
Q

Object

A

An instance of a particular class. In general, any number of objects may be constructed from a class definition (see singleton, however). The class to which an object belongs defines the general characteristics of all instances of that class. Within those characteristics, an object will behave according to the current state of its attributes and environment.

50
Q

Object serialization

A

The writing of an object’s contents in such a way that its state can be restored, either at a later time, or within a different process. This can be used to store objects between runs of a program, or to transfer objects across a network, for instance.

51
Q

Package

A

A named grouping of classes and interfaces that provides a package namespace. Classes, interfaces and class members without an explicit public, protected or private access modifier {access!modifier} have package visibility. Public classes and interfaces may be imported into other packages via an import statement.

52
Q

Polymorphism

A

The ability of an object reference to be used as if it referred to an object with different forms. Polymorphism in Java results from both class inheritance and interface inheritance. The apparently different forms often result from the static type of the variable in which the reference is stored. Given the following class header

class Rectangle extends Polygon implements Comparable

an object whose dynamic type is Rectangle can behave as all of the following types: Rectangle, Polygon, Comparable, Object.

53
Q

Shallow copy

A

A copy of an object in which copies of all the object’s sub-components are not also made. For instance, a shallow copy of an array of objects would result in two separate array objects, each containing references to the same set of objects as were stored in the original. See deep copy for an alternative.

54
Q

Single inheritance

A

In Java, a class may not extend more than one class. This means that Java has a single inheritance model for class inheritance. See multiple inheritance for the alternative.

55
Q

Statement

A

The basic building block of a Java method. There are many different types of statement in Java, for instance, the assignment statement, if statement, return statement and while loop.

56
Q

Statement terminator

A

The semicolon (;) is used to indicate the end of a statement.

57
Q

Static method

A

Static methods differ from all other methods in that they are not associated with any particular instance of the class to which they belong. They are usually accessed directly via the name of the class in which they are defined.

58
Q

Static variable

A

Such a variable belongs to the class as a whole, and is, therefore, shared by all objects of the class. A class variable might be used to define the default value of an instance variable, for example, and would probably also be defined as final, too. They are also used to contain dynamic information that is shared between all instances of a class. For instance the next account number to be allocated in a bank account class. Care must be taken to ensure that access to shared information, such as this, is synchronized where multiple threads could be involved. Class variables are also used to give names to application-wide values or objects since they may be accessed directly via their containing class name rather than an instance of the class.

59
Q

Sub class

A

A class that extends its super class. A sub class inherits all of the members of its super class. All Java classes are sub classes of the Object class, which is at the root of the inheritance hierarchy. See sub type

60
Q

Super class

A

A class that is extended by one or more sub classes. All Java classes have the Object class as a super class. See super type.

61
Q

Super type

A

A type with a child sub type. The sub-type/super-type relationship is more general than the sub-class/super-class relationship. An interface that is implemented by a class is a super type of the class. An interface that is extended by another interface is also a super type.

62
Q

Thread

A

A lightweight process that is managed by the Java Virtual Machine (JVM). Support for threads is provided by the Thread class in the java.lang package.

63
Q

Wrapper classes

A

Java’s primitive types are not object types. The wrapper classes are defined in the java.lang package. They consist of a class for each primitive type: Boolean, Byte, Character, Double, Float, Integer, Long and Short. These classes provide methods to parse strings containing primitive values, and turn primitive values into strings. The Double and Float classes also provide methods to detect special bit patterns for floating point numbers, representing values such as NaN, +infinity and -infinity.

64
Q

Accessor and Mutator

A

Let’s go over the basics: “Accessor” and “Mutator” are just fancy names fot a getter and a setter. A getter, “Accessor”, returns a class’s variable or its value. A setter, “Mutator”, sets a class’s variable or its value.

65
Q

Attribute vs Property

A

In general terms (and in normal English usage) the terms mean the same thing.

In the specific context of HTML / Javascript the terms get confused because the HTML representation of a DOM element has attributes (that being the term used in XML for the key/value pairs contained within a tag) but when represented as a JavaScript object those attributes appear as object properties.

To further confuse things, changes to the properties will typically update the attributes.

For example, changing the element.href property will update the href attribute on the element, and that’ll be reflected in a call to element.getAttribute(‘href’).

However if you subsequently read that property, it will have been normalised to an absolute URL, even though the attribute might be a relative URL!

66
Q

Dynamic vs Static type

A

Statically typed programming languages do type checking (the process of verifying and enforcing the constraints of types) at compile-time as opposed to run-time.

Dynamically typed programming languages do type checking at run-time as opposed to Compile-time.

67
Q

Field vs Property

A

Properties expose fields. Fields should (almost always) be kept private to a class and accessed via get and set properties. Properties provide a level of abstraction allowing you to change the fields while not affecting the external way they are accessed by the things that use your class.

```csharp
public class MyClass
{
// this is a field. It is private to your class and stores the actual data.
private string _myField;

    // this is a property.  When you access it uses the underlying field, but only exposes
    // the contract that will not be affected by the underlying field
    public string MyProperty
    {
        get
        {
            return _myField;
        }
        set
        {
            _myField = value;
        }
    }
}

~~~

68
Q

Concurrency and Parallelism

A

Concurrency and parallelism are two related but distinct concepts. Concurrency means, essentially, that task A and task B both need to happen independently of each other, and A starts running, and then B starts before A is finished.

There are various different ways of accomplishing concurrency. One of them is parallelism–having multiple CPUs working on the different tasks at the same time. But that’s not the only way. Another is by task switching, which works like this: Task A works up to a certain point, then the CPU working on it stops and switches over to task B, works on it for a while, and then switches back to task A. If the time slices are small enough, it may appear to the user that both things are being run in parallel, even though they’re actually being processed in serial by a multitasking CPU.

69
Q

Abstract class

A

Abstract classes are classes that contain one or more abstract methods. An abstract method is a method that is declared, but contains no implementation. Abstract classes may not be instantiated, and require subclasses to provide implementations for the abstract methods. Let’s look at an example of an abstract class, and an abstract method.

```java
public abstract Animal
{
public void eat(Food food)
{
// do something with food….
}

   public void sleep(int hours)
   {
        try
    {
        // 1000 milliseconds * 60 seconds * 60 minutes * hours
        Thread.sleep ( 1000 * 60 * 60 * hours);
    }
    catch (InterruptedException ie) { /* ignore */ }
   }

public abstract void makeNoise();
}
~~~

```java
{
public void makeNoise() { System.out.println (“Bark! Bark!”); }
}

public Cow extends Animal
{
   public void makeNoise() { System.out.println ("Moo! Moo!"); }
}

~~~