Design Pattern

1. What is Singleton Pattern?

The Singleton design pattern ensures that only one instance exists for a given class and that there’s a global access point to that instance. It usually uses lazy loading to create the single instance when it’s needed the first time.

  • They violate the single responsibility principle
  • They carry state around for the lifetime of the application
  • They inherently cause code to be tightly coupled.

2. What is the delegation pattern?

  • The basic idea is that one object will act on another object's behalf or in coordination with another object.
  • The delegating object typically keeps a reference to the other object (delegate) and sends a message to it at the appropriate time.
  • It is important to note that they have a one to one relationship.

3. What is extension and category?

  • Allows you to add new functionality to existing classes, structures or enumeration types without having to subclass.
  • You can even extend code you don't have access to, and enhance their functionality.
  • This means that you can add your own methods to Cocoa Classes.
  • Extensions are similar to categories in Objective-C. (Unlike Objective-C categories, Swift extensions do not have names.)

4. What's the difference between using a delegate and notification?

  • A delegate is for one-to-one communication.
  • In delegation the class raising events will have a property for the delegate and will typically expect it to implement some protocol.
  • Notification allows a class to broadcast events across the entire application to any interested parties.
  • The broadcasting class doesn't need to know anything about the listeners for this event

5. What is a protocol? How do you define your own protocol?

A protocol defines a list of required and optional methods for a class that adopts the protocol to implement. Any class is allowed to implement a protocol so that other classes can send message to it based on the protocol methods without knowing the type of class.

What is MVC?

MVC stands for Model-View-Controller. It is a software architecture pattern for implementing user interfaces.

  • MVC consists of three layers: the model, the view, and the controller.
  • The model layer is typically where the data resides (persistence, model objects, etc)
  • The view layer is typically where all the UI interface lies. Things like displaying buttons and numbers belong in the view layer. The view layer does not know anything about the model layer and vice versa.
  • The controller (view controller) is the layer that integrates the view layer and the model layer together.

What is MVVM?

  • MVVM stands for Model-View-ViewModel. It is a software architecture pattern for implementing user interfaces.
  • MVVM is an augmented version of MVC where the presentation logic is moved out of the controller and into the view model.
  • The view model is responsible for handling most, if not all, of the view's display logic.

results matching ""

    No results matching ""