I
I
IgorRastvorov2014-05-01 12:52:37
Android
IgorRastvorov, 2014-05-01 12:52:37

Compliance with the OCP principle regarding the controller when developing Android applications?

Actually, there was such a question. This principle is observed when designing business entities (i.e. models in the MVC pattern), but when designing activities, the principle of openness / closeness is not very well observed. Is this due to the fact that the controller is not an object that models some entity of the subject area?
Code example where this principle is violated :

class MainActivity extends Activity
{
         private void someMethod()
         {
                  SuperClassName objectName = new SubClassName(); // здесь нарушается принцип OCP 
                  ...
         }
}

Of course, to solve this problem, you can pass a reference to the derived class as a parameter to the "someMethod" method. Only the client code should do it. Apparently, the activity is already the client code. So?
An example of code where this principle is observed :
class MainActivity extends Activity
{
         private void someMethod(SuperClassName objectName)
         {
                  objectName.methodName();
                  ...
         }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question