I've built a pseudo inheritance since mql doesn't allow this, here's what i did.
I want to improve this part:
is there a way to add CLocalShop object and automatically pass CVendorAux if the collection is of CVendor object? same for CCustomer?
any other things to improve or correct? i'm asking the veteran here, i'm trying to learn best practice and pattern for coding, i've no experince exept mql.
thanks
edit: accidentally posted thread without finishing it and formatting
This is not really a good example of inheritance since your objects do not maintain the "IS A" relationship. A local shop is a vendor? A local shop is a customer?
A better example is if you have a class that needs to implement more than one base class.
class Base1 { virtual int Type()=0; }; class Base2 { virtual string ToString()=0; };
Let's say you had an existing class that derived Base1
class MyClass : public Base1 {};
Now Let's say you needed MyClass to also inherit Base 2. Without multiple inheritance you would need to fork the class and declare it like this.
class Base1 { virtual int Type()=0; }; class Base2 : public Base1 { virtual string ToString()=0; }; class MyClass : public Base2 {};
...
any other things to improve or correct? i'm asking the veteran here, i'm trying to learn best practice and pattern for coding, i've no experince exept mql.
...
In my opinion, a best practice is to not "force" a pattern usage when the language doesn't provide all the needed features.
Multiple inheritance is not a requirement for the pattern.
This topic is linked to this one Observer pattern, right ?
So, if multiple inheritance is not required, it is needed if someone is trying to code "pseudo" multiple inheritance (I am talking about multiple inheritance of interface or any other form), coding it without a kind of inheritance is possible but is a limitation, and need to think about it carefully for the pattern to remain useful. Of course you can always find tricks to have it "working", I have even read about copy and paste as an OOP "technique" (isn't OOP about code re-usability ?). Or you can implement the subject/observer "interfaces" in the super class <CObject>, but while doing that you need to be aware of the possible consequences.
Why and when is the Observer pattern needed and usable ? From the "Design Patterns: Elements of Reusable Object-Oriented Software" (from the well known Gang of Four or GoF), we can read that :
When an abstraction has two aspects, one dependent on the other. Encapsulating these aspects in separate objects lets you vary and reuse them independently.
When a change to one object requires changing others, and you don't know how many objects need to be changed.
When an object should be able to notify other objects without making assumptions about who these objects are. In other words, you don't want these objects tightly coupled.
Are your objects reusable and independent ? are they not-tightly coupled ? If the way you coded them and use the Observer pattern lead to answer in a negative way to these questions, then the purpose to use this pattern is defeated.
OOP is a good programming paradigm, design patterns are great best practices...if used correctly and lead to better code.
So, are your objects reusable, independent, not-tightly coupled ? I have some difficulties to think all the proposed implementation will answer yes to all these questions. That doesn't mean it's not worth to implement the Observer pattern in the way you want, to have a functional code, of course, but don't expect to be able to reuse it later in an other project if it's not well conceived.
At the bottom of this post, you will see an implementation using templates, and which doesn't use multiple inheritance. Why not try it in mql5 ?
Finally some news ...
Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий
Renat Fatkhullin, 2017.12.22 22:59
Будет скоро- Corneliu Tusnea
- www.codeproject.com
This topic is linked to this one Observer pattern, right ?
So, if multiple inheritance is not required, it is needed if someone is trying to code "pseudo" multiple inheritance (I am talking about multiple inheritance of interface or any other form), coding it without a kind of inheritance is possible but is a limitation, and need to think about it carefully for the pattern to remain useful. Of course you can always find tricks to have it "working", I have even read about copy and paste as an OOP "technique" (isn't OOP about code re-usability ?). Or you can implement the subject/observer "interfaces" in the super class <CObject>, but while doing that you need to be aware of the possible consequences.
Why and when is the Observer pattern needed and usable ? From the "Design Patterns: Elements of Reusable Object-Oriented Software" (from the well known Gang of Four or GoF), we can read that :
Are your objects reusable and independent ? are they not-tightly coupled ? If the way you coded them and use the Observer pattern lead to answer in a negative way to these questions, then the purpose to use this pattern is defeated.
OOP is a good programming paradigm, design patterns are great best practices...if used correctly and lead to better code.
So, are your objects reusable, independent, not-tightly coupled ? I have some difficulties to think all the proposed implementation will answer yes to all these questions. That doesn't mean it's not worth to implement the Observer pattern in the way you want, to have a functional code, of course, but don't expect to be able to reuse it later in an other project if it's not well conceived.
At the bottom of this post, you will see an implementation using templates, and which doesn't use multiple inheritance. Why not try it in mql5 ?
Finally some news ...
Are you trying to say that cloning some classes into your project folder and making minor tweaks to those classes in order to suit the needs of your project -- is not good OOP practice??? I hate to be the one to break it to you, but cloning and forking code is an extremely common practice in the real world.
This topic is linked to this one Observer pattern, right ?
So, if multiple inheritance is not required, it is needed if someone is trying to code "pseudo" multiple inheritance (I am talking about multiple inheritance of interface or any other form), coding it without a kind of inheritance is possible but is a limitation, and need to think about it carefully for the pattern to remain useful. Of course you can always find tricks to have it "working", I have even read about copy and paste as an OOP "technique" (isn't OOP about code re-usability ?). Or you can implement the subject/observer "interfaces" in the super class <CObject>, but while doing that you need to be aware of the possible consequences.
Why and when is the Observer pattern needed and usable ? From the "Design Patterns: Elements of Reusable Object-Oriented Software" (from the well known Gang of Four or GoF), we can read that :
Are your objects reusable and independent ? are they not-tightly coupled ? If the way you coded them and use the Observer pattern lead to answer in a negative way to these questions, then the purpose to use this pattern is defeated.
OOP is a good programming paradigm, design patterns are great best practices...if used correctly and lead to better code.
So, are your objects reusable, independent, not-tightly coupled ? I have some difficulties to think all the proposed implementation will answer yes to all these questions. That doesn't mean it's not worth to implement the Observer pattern in the way you want, to have a functional code, of course, but don't expect to be able to reuse it later in an other project if it's not well conceived.
At the bottom of this post, you will see an implementation using templates, and which doesn't use multiple inheritance. Why not try it in mql5 ?
Finally some news ...
Good news form MetaQuotes, guess i'll wait for multi inheritance support.
Multiple inheritance is not a requirement for the pattern.
Of course it is a requirement, and you can also bypass it with consequences as Alain said.
For instance, your code does not support an observer that observes several subjects.
And you did not inherit Subject into a concrete subject, which makes the example useless.
I don't say you can not overcome those, you can. But they are flaws right now.
BTW, I use observer for few years now.
* Actually, you need to inherit subject + inherit observer - which you didn't do.
Of course it is a requirement, and you can also bypass it with consequences as Alain said.
For instance, your code does not support an observer that observes several subjects.
And you did not inherit Subject into a concrete subject, which makes the example useless.
I don't say you can not overcome those, you can. But they are flaws right now.
BTW, I use observer for few years now.
* Actually, you need to inherit subject + inherit observer - which you didn't do.
This is a total straw man argument you setup here. You can rewrite the class to implement the same interfaces as it would with multiple inheritance by cloning the class and forking it's code. Just because I did a simple conversion from the Java example and didn't waste the time in making a fully working mql snippet doesn't change the fact that if I want a mql class to implement multiple interfaces then I can easily change its declarations to do so.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I've built a pseudo inheritance since mql doesn't allow this, here's what i did.
I want to improve this part:
is there a way to add CLocalShop object and automatically pass CVendorAux if the collection is of CVendor object? same for CCustomer?
any other things to improve or correct? i'm asking the veteran here, i'm trying to learn best practice and pattern for coding, i've no experince exept mql.
thanks
edit: accidentally posted thread without finishing it and formatting