Object Oriented Programming Flashcards
What is OOP?
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.
What is a Class?
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 { }
What is an Object?
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.
What are Methods?
Methods add behaviour to classes and instances.
What are Properties?
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.
What is an Override method?
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).
What is a Base Class?
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.
What are Protocols in Swift / Objective-C?
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 can you make a Protocol method Optional in Swift?
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 does a Class conform to a Protocol in Swift?
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 { ... }
What is a Delegate?
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.
What is a Singleton?
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.
What is MVC?
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.
What are the benefits of MVC?
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.
What are Model Objects?
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.