Download MetaTrader 5

Is it possible to create an Abstract Class in mql5?

To add comments, please log in or register
Your broker does not support mobile MetaTrader 5? Ask him to buy them!
Luis Sampaio
146
Luis Sampaio 2013.11.19 20:44 

Hi Guys,

 I'm wondering if is it possible to create an Abstract Class in mlq5?

 For example, like we use in Java:

http://docs.oracle.com/javase/tutorial/java/IandI/abstract.html

 

Java Code:


abstract class GraphicObject {
    int x, y;
    ...
    void moveTo(int newX, int newY) {
        ...
    }
    abstract void draw();
    abstract void resize();
}

class Circle extends GraphicObject {
    void draw() {
        ...
    }
    void resize() {
        ...
    }
}
class Rectangle extends GraphicObject {
    void draw() {
        ...
    }
    void resize() {
        ...
    }
}
Abstract Methods and Classes (The Java™ Tutorials > Learning the Java Language > Interfaces and Inheritance)
  • docs.oracle.com
An abstract class is a class that is declared —it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed. An abstract method is a method that is declared without an implementation (without braces, and followed by a semicolon), like this: If a class includes...
Alain Verleyen
Moderator
30755
Alain Verleyen 2013.11.20 14:09  
luisf:

Hi Guys,

 I'm wondering if is it possible to create an Abstract Class in mlq5?

 For example, like we use in Java:

http://docs.oracle.com/javase/tutorial/java/IandI/abstract.html

 

There is no abstract class in mql5. But you can use a "normal" class and declare its method as virtual. The only difference, I think, is you can instantiated this class in mql5.

Please read the documentation.

Luis Sampaio
146
Luis Sampaio 2013.11.21 12:42  
angevoyageur:

There is no abstract class in mql5. But you can use a "normal" class and declare its method as virtual. The only difference, I think, is you can instantiated this class in mql5.

Please read the documentation.

That was exactly what I was looking for.  Also I found this very useful article that has a section talking about virtual functions: https://www.mql5.com/en/articles/351

Thanks!!
The Basics of Object-Oriented Programming
The Basics of Object-Oriented Programming
  • 2011.12.07
  • Dmitry Fedoseev
  • www.mql5.com
You don't need to know what are polymorphism, encapsulation, etc. all about in to use object-oriented programming (OOP)... you may simply use these features. This article covers the basics of OOP with hands-on examples.
Dua Yong Rew
5423
Dua Yong Rew 2013.11.22 03:30  
I have yet to use classes in my EA. I think my EA are very simple.
Pasi Hakamaki
4736
Pasi Hakamaki 2013.11.23 21:39  
doshur:
I have yet to use classes in my EA. I think my EA are very simple.
I have started to learn and can recommed these.
To add comments, please log in or register