Object Oriented Programming Flashcards

1
Q

What is OOP?

A

Object-oriented programming (OOP) is a programming paradigm based on the concept of “objects”, which are data structures that contain data, in the form of fields, often known as attributes or properties; and code, in the form of procedures, often known as methods.

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

What is a Class?

A

In object-oriented programming, a class is an extensible program-code-template for creating objects, providing initial values for state (member variables) and implementations of behavior (member functions, methods). In other words, a class is like a blueprint, it defines the data and behavior of a type.

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

What is an Object?

A

An Object is an Instance of a Class. An object is a software bundle of related state and behavior. Software objects are often used to model the real-world objects that you find in everyday life.

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

What are Methods?

A

Methods add behaviour to classes and instances.

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

What are Properties?

A

Classes and instances can have associated values named properties. The usual use of properties are instance properties, like the length of a Square. You can also have Class Properties. Properties are also called variables. Instance Variables, Class Variables are the same thing as Instance Properties and Class Properties.

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

What is an Override method?

A

You can override methods in order to provide custom behaviour. To override a method write the override keyword before the method declaration. You can use the super keyword to call any method from the superclass (in Swift).

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

What is a Base Class?

A

A class that does not inherit from another class is called a base class. The iOS and Mac OS classes usually inherit from NSObject, either directly or indirectly.

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

What are Protocols in Swift / Objective-C?

A

Protocols describe methods, properties and other requirements that are needed for a specific task. For example theUITableViewDelegate protocol lists all the methods that can be used to react to user events and configure a table view. Protocols use the same syntax as normal methods, but are not allowed to specify default values for method parameters.

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

How can you make a Protocol method Optional in Swift?

A

You can mark a method as optional using the @optional keyword. All of the methods fromUITableViewDelegate are optional. When you do not use the @optional keyword that method is required. The swift compiler will throw an error if a class conforms to a protocol and does not implement the required methods.

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

How does a Class conform to a Protocol in Swift?

A

A class can conform to a protocol by placing its name after the type’s name separated by a colon, as part of their definition. Multiple protocols can be listed, and are separated by commas:

class AnotherSwiftClass: MyFirstProtocol, AnotherProtocol {
    ...
}
If a class inherits from another one, make sure to put the superclass name before the protocol list.
class AnotherSwiftClass: AClass, MyFirstProtocol, AnotherProtocol {
    ...
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a Delegate?

A

A very popular design pattern in iOS is delegation. A class can delegate a part of it’s responsibilities to an instance of another class. This design pattern is implemented by defining a protocol that encapsulates the delegated responsibilities, such that a conforming type (known as a delegate) is guaranteed to provide the functionality that has been delegated.

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

What is a Singleton?

A
A Singleton is a programming Design Pattern.
Sometimes it’s important to have only one instance for a class. For example, in a system there should be only one window manager. The important part is making sure that there is only one instance of a class running in your app / game at any given time.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is MVC?

A

The Model-View-Controller (MVC) design pattern assigns objects in an application one of three roles: model, view, or controller. The pattern defines not only the roles objects play in the application, it defines the way objects communicate with each other. Each of the three types of objects is separated from the others by abstract boundaries and communicates with objects of the other types across those boundaries. The collection of objects of a certain MVC type in an application is sometimes referred to as a layer—for example, model layer.

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

What are the benefits of MVC?

A

The benefits of adopting this pattern are numerous. Many objects in these applications tend to be more reusable, and their interfaces tend to be better defined. Applications having an MVC design are also more easily extensible than other applications. Moreover, many Cocoa technologies and architectures are based on MVC and require that your custom objects play one of the MVC roles.

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

What are Model Objects?

A

Model objects encapsulate the data specific to an application and define the logic and computation that manipulate and process that data. For example, a model object might represent a character in a game or a contact in an address book. A model object can have to-one and to-many relationships with other model objects, and so sometimes the model layer of an application effectively is one or more object graphs. Much of the data that is part of the persistent state of the application (whether that persistent state is stored in files or databases) should reside in the model objects after the data is loaded into the application. Because model objects represent knowledge and expertise related to a specific problem domain, they can be reused in similar problem domains. Ideally, a model object should have no explicit connection to the view objects that present its data and allow users to edit that data—it should not be concerned with user-interface and presentation issues.

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

What are View Objects?

A

A view object is an object in an application that users can see. A view object knows how to draw itself and can respond to user actions. A major purpose of view objects is to display data from the application’s model objects and to enable the editing of that data. Despite this, view objects are typically decoupled from model objects in an MVC application.

Because you typically reuse and reconfigure them, view objects provide consistency between applications. Both the UIKit and AppKit frameworks provide collections of view classes, and Interface Builder offers dozens of view objects in its Library.

20
Q

What are Controller Objects?

A

A controller object acts as an intermediary between one or more of an application’s view objects and one or more of its model objects. Controller objects are thus a conduit through which view objects learn about changes in model objects and vice versa. Controller objects can also perform setup and coordinating tasks for an application and manage the life cycles of other objects.

21
Q

Describe Communication with Model Objects.

A

Communication: User actions in the view layer that create or modify data are communicated through a controller object and result in the creation or updating of a model object. When a model object changes (for example, new data is received over a network connection), it notifies a controller object, which updates the appropriate view objects.

22
Q

Describe Communication with View Objects.

A

Communication: View objects learn about changes in model data through the application’s controller objects and communicate user-initiated changes—for example, text entered in a text field—through controller objects to an application’s model objects.

23
Q

What is an Interface?

A

An interface is a contract between a class and the outside world. When a class implements an interface, it promises to provide the behavior published by that interface. Interfaces in Java and C# are the same as Protocols in Objective-C and Swift.

24
Q

What is an Abstract Class?

A

Abstract classes, which are declared with the abstract keyword, cannot be instantiated. They can only be used as a super-class for other classes that extend the abstract class. Abstract class is the concept and implementation gets completed when it is being realized by a subclass. In addition to this a class can inherit only from one abstract class (but a class may implement many interfaces) and must override all its methods/properties that are declared to be abstract and may override virtual methods/ properties.

25
Q

Describe Communication with Controller Objects.

A

Communication: A controller object interprets user actions made in view objects and communicates new or changed data to the model layer. When model objects change, a controller object communicates that new model data to the view objects so that they can display it.

27
Q

What is Inheritance?

A

Inheritance means that objects of one class can derive part of their behavior from another (base or parent) class. A class can inherit methods, properties, and other characteristics from another class. When one class inherits from another, the inheriting class is known as a subclass, and the class it inherits from is known as its superclass.

29
Q

What is Encapsulation?

A

Encapsulation is the packing of data and functions into a single component. The features of encapsulation are supported using classes in most object-oriented programming languages, although other alternatives also exist. It allows selective hiding of properties and methods in an object by building an impenetrable wall to protect the code from accidental corruption.
Encapsulation means that objects keep their state information private. Rather than directly manipulating an object’s data, other objects send requests to the object, in the form of messages, some of which the object may respond to by altering its internal state.

30
Q

What is Polymorphism?

A

Polymorphism means that objects of different classes can be used interchangeably. This is especially important, as it allows you to hook up classes at a later date in ways you didn’t necessarily foresee when those classes were first designed. Polymorphism means “having multiple forms”. Objects of different classes can be used interchangeably if they have a common superclass.

31
Q

What is dynamic dispatch / message passing?

A

By definition, it is the responsibility of the object, not the external code, to select the procedural code to run in response to a method call, typically by looking up the method at run time in a table associated with the object. This feature is known as dynamic dispatch, and distinguishes an object from an abstract data type (or module), which has a fixed (static) implementation of the operations for all instances. If there are multiple methods that might be run for a given name (which may require some language support), it is known as multiple dispatch.

A method call is also known as message passing. It is conceptualized as a message (the name of the method and its input parameters) being passed to the object for dispatch.

32
Q

What is Composition?

A

Objects can contain other objects in their instance variables; this is known as object composition. For example, an object in the Employee class might contain (point to) an object in the Address class, in addition to its own instance variables like “first_name” and “position”. Object composition is used to represent “has-a” relationships: every employee has an address, so every Employee object has a place to store an Address object.

33
Q

What are Instance Variables?

A

In object-oriented programming with classes, an instance variable is a variable defined in a class (i.e. a member variable), for which each instantiated object of the class has a separate copy, or instance. An instance variable is similar to a class variable, but not the same. Another way of saying that is instance variables belong to an object, since an object is an instance of a class. Every object has it’s own copy of the instance variables.

34
Q

What are Class Variables?

A

Class variables only have one copy of the variable(s) shared with all instances of the class. It’s important to remember that class variables are also known as static member variables in C++, Java, and C#. Each object of the class does not have its own copy of a class variable. Instead, every object shares the one and only copy of that class variable – and any changes made to that copy are seen by all of the objects of that class.

35
Q

What’s the difference between Class Variables and Instance Variables?

A

Class variables only have one copy that is shared by all the different objects of a class, whereas every object has it’s own personal copy of an instance variable. So, instance variables across different objects can have different values whereas class variables across different objects can have only one value.

36
Q

What are Member Variables?

A

Member variables - refers to the both class and instance variables that are defined by a particular class

37
Q

What is Open Recursion?

A

In languages that support open recursion, object methods can call other methods on the same object (including themselves), typically using a special variable or keyword called this or self. This variable is late-bound; it allows a method defined in one class to invoke another method that is defined later, in some subclass thereof.