Discussion of article "MVC design pattern and its application (Part 2): Diagram of interaction between the three components"

 

New article MVC design pattern and its application (Part 2): Diagram of interaction between the three components has been published:

This article is a continuation and completion of the topic discussed in the previous article: the MVC pattern in MQL programs. In this article, we will consider a diagram of possible interaction between the three components of the pattern.

The resulting Controller method which is called in the OnChartEvent handler of the main indicator file looks as follows:

void CController::ChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam) {

      switch (id) {
         case CHARTEVENT_OBJECT_CLICK:
            if (StringCompare(sparam, pBtn.GetName()) == 0) {
               if (pView.GetViewType() == LINE)
                  pView.SetNewViewType(HISTO);
               else pView.SetNewViewType(LINE);   
            }
            break;      
        default:
            break;    
      }//switch (id)
}


The method checks whether the mouse was clicked on the right object, and then it switched the display mode in the View:

It was quite easy and quick to add the relevant changes. If we had to perform similar changes a year later, it wouldn't take much longer. The developer remembers the structure of the script and what is done in each of the components. So, the project is easy to maintain even if documentation is lost or if you forget the project principles.

Author: Andrei Novichkov

 
Andrei, thank you for the article.

I would like to add some ideas to your project...

1. In input parameters you can use unsigned types, then the terminal simply does not allow the user to enter negative values, for example uint.

2. I do not recommend overriding the parameters on the input to the default value, otherwise when you will use the strategy tester, you will get a lot of identical runs and not only for this reason, the second point is that it is hidden from the eyes and the user will not realise that it makes a mistake, it is better to tell about the error and stop working.

3. I recommend using dictionaries for storing data and variables in your case they will fit perfectly, the code can be reduced in times even in large projects.

4. Use standard classes of the terminal, for example, to create indicators, etc. Do not make bicycles, hardly your code will be used by experienced developers, but you will very much pump up the skill using standard classes.

5. Use virtual methods, where it is allowed, to untie the hands of other developers who will use your classes and inherit from them, so that they do not modify your class directly.
 
Thanks for the comment. I present the article (all my articles) as something that encourages a reaction, an independent creation. By no means as a dogma. That is why your comments are very helpful, you can learn a lot of useful things from them.
 

There's a lack of inferior bar on the horizontal visualization of Metatrader 5 for cell phone. The bar whose shows "Quotes,/Charts/Trade/History/Messages" doesn't is accessible from the horizontal view of screen. The utilizer needs to turn up the smartphone 📲 in order to access the "Quotes/Chart/Trade/History/Messages" bar.

The video can specify what I'm saying.