So, it’s time to publish another batch of questions and answers for interviews that will be useful to both beginners and experienced iOS developers.
WHAT IS POLYMORPHISM?
Answer: Polymorphism is the basic principle of OOP. The bottom line is that one and the same method of different heirs has its own implementation.
In short, polymorphism is the ability of an object to use the methods of a derived class that does not exist at the time of the creation of the base class. For those who are not particularly versed in the PLO, this probably sounds difficult. Therefore, consider the application of polymorphism by example.
The definition of polymorphism as “one interface – many implementations”, popularized by Bjarne Stroustrup, refers to ad-hoc polymorphism, but in reality, ad-hoc polymorphism is not a true polymorphism.
Polymorphism is the ability to work with several types as if it were the same type and at the same time the behavior of each type will be unique, depending on its implementation.
Polymorphism can be:
A classic example of a polymorphic type is a list of elements of an arbitrary type.
WHAT IS ENCAPSULATION? WHAT IS A VIOLATION OF ENCAPSULATION?
Answer: Encapsulation is a fundamental object-oriented concept that allows you to pack data and behavior into a single component, dividing it into separate parts – the interface and implementation.
Another version of the definition:
The mechanism of the language, which allows you to restrict access to some components of the program to others;
a language construct that allows you to associate data with methods designed to process this data.
Simply put: we hide the implementation from the user, providing it with an interface. As a class or method is implemented in fact – the user does not need to know.
HOW DOES THE ABSTRACT CLASS DIFFER FROM THE INTERFACE?
Answer: An abstract class is a class that does not have one or more methods implemented (some languages require special keywords to mark such methods).
The interface is an abstract class, in which all methods are not implemented, all public and there are no class variables.
The interface is usually needed when only the interface is described. For example, one class wants to give another the opportunity to access some of its methods but does not want to “disclose” itself. Therefore, it simply implements the interface.
An abstract class is needed when you need a family of classes that have much in common. Of course, you can apply the interface, but then you will need to write a lot of identical code.
In some languages (C ++) there is no special keyword for interfaces. We can assume that an interface is an abstract class, but not vice versa.
TELL US ABOUT THE MVC PATTERN. WHAT IS THE DIFFERENCE BETWEEN A PASSIVE MODEL AND AN ACTIVE ONE?
Answer: Model-view-controller (MVC, “model-view-controller”, “model-view-controller”) is a scheme of using several design patterns by means of which the application model, user interface and user interaction are divided into three separate components so that the modification of one of the components had a minimal effect on the rest. Such a design pattern is often used to construct an architectural framework when moving from theory to implementation in a particular subject area.
In the original concept, the very idea and role of each of the elements were described: model, representation and controller. But the connections between them were described without specification. In addition, there were two main modifications:
Passive model – The model has no means of influencing the view or controller and is used by them as a data source for display. All changes to the model are monitored by the controller and it is responsible for redrawing the view, if necessary. Such a model is more often used in structural programming, since in this case, the model is simply a data structure, without methods of processing them;
Active model – The model notifies about changes in it those representations that subscribed to receive such notifications. This allows the model to remain independent of controllers and views.