Polymorphism or Interfaces?

Hi,

I’ve never used Interfaces and is now trying to figure out when Interfaces is a good thing use vs Polymorphism:

What is the advantage with Interfaces over Polymorphism?

What is the advantage with Polymorphism over Interfaces ?

Interfaces IS how Xojo does polymorphism. There is no either/or.

Thanks, maybe I’m using the wrong words here:

I probably mean “inheritance and overriding” (Class and subclassing) vs Interfaces…

One of the guiding principles of OO programming is “favor composition over inheritance”. Larger chains of classes can become brittle. So you need to tell us what you want to do before we can recommend something.

Good point,

In this case I want to create modules that a user can select. One or many.
These modules can perform various actions: Copy file, Send file with FTP etc.

So I was thinking that I make a BaseActionClass which I then subclass to CopyFileClass, SendFileClass.
These classes have some properties common and some not common.

If the actions are similar use classes with subclass. If they are not, use interfaces. An interface is the possibility to treat objects that are not the same as having similar actions.

Primitive example, nothing to do with programming. You got a house. You can tell all objects that understand the “open” message to do their stuff. Doesn’t matter if it’s a door, a window, an american sliding window, a sliding door or whatever. Each object knows what do to. For classes you need to define relationships. You have openings, then you define square openings, you define square openings with sliders or with knob and so on. More precise, more work.

It’s the intent that varies. You need to decide what’s in your actions. And you can always do a refactoring if your design doesn’t cut it anymore.

Thanks!

to create modules with global methods like you’re naming, you can use … modules !
no need for classes or subclasses or inheritence or so !

It is not Xojo modules I’m talking about it is modules seen from the endusers perspective.

But thanks anyhow!