Questions on OOP in MQL5 - page 23

 
Vladimir Simakov:
I'll show you later tonight. Now from my phone.

OK

It's not a problem to remove inheritance from interface, you can inherit from a base class, but in my opinion there will be confusion in the code - it will be harder to understand which method will be called, and with this code structure - "OOP pattern - Patterns of behavior - Strategy".

I'm always and guaranteed to have one constructor in each strategy, it seems these constructors aren't needed yet... but I'll leave this possibility, it's not superfluous

ZS: the base class itself for all strategies is pretty compact too, about that:

class CStrategy: public IStrategy
{
protected:
   SSettingsForOrder  m_setting;
   COrder *m_order;
   void RunStrategy();
   double CalcLot();
   double GetPrice(); 
};

So far I like that code structure is readable and logical, and the most important thing "in all this stuff" is to make some kind of prototype, which will allow to quickly add strategies itself and test them.

I had already written everything in principle, but I don't like the code - I wrote it in the form of service functions (to open order, lot calculation etc.) in procedural style and then I wrote small classes with logic and calls of these service functions and decided to make it as good as possible)))

 
Igor Makanu:

OK

It's not a problem to remove inheritance from interface, you can inherit from a base class, but in my opinion there will be confusion in the code - it will be harder to understand which method will be called, and with this code structure - "OOP pattern - Patterns of behavior - Strategy".

I'm always and guaranteed to have one constructor in each strategy, it seems these constructors aren't needed yet... but I'll leave this possibility, it's not superfluous

ZS: the base class itself for all strategies is pretty compact too, about that:

So far I like that code structure is readable and logical, and the most important thing "in all this stuff" is to make some kind of prototype, which will allow to quickly add strategies itself and test them.

I had already written everything in principle, but I don't like the code - I wrote service functions (to open an order, calculate lots, etc.) in procedural style and then I wrote small classes with logic and calls of these service functions and decided to make it as good as possible)))

//+------------------------------------------------------------------+
class CStrategy
{
protected:
   int x;
public:
   CStrategy(int _x):x(_x){}
   virtual void Algorithm()=0;};
//+------------------------------------------------------------------+
class CStrategy_01:public CStrategy
{
public:
   CStrategy_01():CStrategy(1) {Print(__FUNCTION__);}
   void Algorithm()                 {Print(__FUNCTION__,", x = ",x);       } };
//+------------------------------------------------------------------+
class CStrategy_02:public CStrategy
{
public:
   CStrategy_02():CStrategy(2) {Print(__FUNCTION__);}
   void Algorithm()                 {Print(__FUNCTION__,", x = ",x);       } };
//+------------------------------------------------------------------+
class Context
{
private:
   CStrategy         *s;
public:
   Context(CStrategy* _strategy):s(_strategy) { Print(__FUNCTION__);}
   ~Context()                       { delete s;                            }
   void              GetStrategy()  { s.Algorithm();                       } };
//+------------------------------------------------------------------+
Context c1(new CStrategy_01);
Context c2(new CStrategy_02);
//+------------------------------------------------------------------+
void OnStart()
{  c1.GetStrategy();
   c2.GetStrategy(); }

That sounds better to me.

 
Vladimir Simakov:

It looks better that way to me.

essentially the same thing, but not by the book! ))))

ZS: I've screwed on the interface anyway, let it be, purely for show!

 
Igor Makanu:

essentially the same thing, but not by the book! ))))

ZS: I've bolted on the interface anyway, let it be, purely for show!

Just in the style of the pros.)))
 
Vladimir Simakov:
Just in the style of pluses.)))

not many people use C#, or rather all application programmers moved to C#, and only large software developers use C#

all examples in C# are via interfaces, so it's clear they're useless .... I don't want to get into a rant, but you can write everything without interfaces, the concept, style... but the concept, style and other brain fog tell me that this is how Microsoft used to write examples in C# - just sit down and write them that way too!

)))

 
Igor Makanu:

not many people use C#, or rather all application programmers moved to C#, and only large software developers use C#

all examples in C# are via interfaces, so it's clear they're useless .... I don't want to get into a rant, but you can write everything without interfaces, the concept, style... but the concept, style and other brain fog tell me that this is how Microsoft used to write examples in C# - just sit down and write them that way too!

)))

Moved because it's inconvenient to write on the pluses under .NET, and Sharp was originally designed as a language for dotnet. That's my personal opinion, at first I wrote pluses on .NET, it felt clumsy.

Although... they've added a lot to the new pros, maybe it's more fun.

 
Alexey Volchanskiy:

We switched because pluses is inconvenient to write on .NET, and Sharp was originally developed as a language for dotnet. This is my subjective opinion, once I wrote in pluses under .NET, I was left with an impression of clumsiness.

Although... they've added a lot to the new pros, maybe it's more fun.

I'm just now writing windows form for one task, touched c++/cli and decided not to use it and printed c#.
 
Vladimir Simakov:
I'm just now writing windows form for one task, touched c++/cli and decided to forget it and printed c#.

Yes, it's easier on sharpe by an order of magnitude. And the speed is almost the same, that's without cli the pros win by a factor and a half.

 
Vladimir Simakov:
I'm just now writing a windows form for one task, touched c++/cli and decided not to use it and printed c#.

I tried to touch cli at the beginning of the year ... I was satisfied for 2 days, the inhuman logic of who made this cli - the syntax is complicated, everything is not convenient, there is very little information with examples, imho or pure C++ or C# - google all the wants, the syntax is clear - as a result, you take and write

 
Igor Makanu:

I tried to touch cli at the beginning of the year ... The syntax is complicated, everything is not convenient, there is very little information with examples, imho - either pure C++ or C# - all desires are googled, syntax is clear - finally you get and you write

Sharp was born around 2000 and was in its infancy, but pluses ruled, so they bridge C++ with Dotnet for popularization. By the way, Sharp was created by Delphi and C++Builder developers, I wondered at that time how many common concepts there are. Take the same properties, events.