Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terminology for relationships defined by interfaces

If inheritance is the OO technique for implementing an is-a relationship and composition/aggregation implements a has-a relationship what would would the appropriate name for the relationship implemented by a Java/.NET style interface be?

I'm really keen on the term can-do relationship since such interfaces are often used to specify supported operations such as Sortable, Clonable etc. plus it sounds really affirmative. The only name that comes to mind that I've actually seen is a realizes relationship but it doesn't really describe all that much.

like image 782
DuncanACoulter Avatar asked Aug 15 '14 09:08

DuncanACoulter


1 Answers

In most Object Oriented Programing Languages, Interfaces and classes both impart their relationship through inheritance, and inheritance is an is-a relationship, regardless of whether it's an interface, class, abstract class, etc...

In fact, classes are themselves interfaces of a sort, they simply also provide an implementation as well. There isn't a huge difference between an abstract class with no implementations and an interface, although the implementation internally may have some differences. (the biggest being that in Java and .NET you can't inherit multiple abstract classes)

So from a conceptual oop perspective, is-a is inheritance. has-a is containment/composition/aggregation/whateveryouwanttocallit,

The term "realizes" is more of a subclass of "inherits" or "subclasses". You can't Subclass an interface, but you can realize it. This is more of fine detail, although it is one that has specific meaning.

Not all languages have interfaces. C++, for instance, doesn't. However, you can fake them with abstract classes with no implementations as I mentioned earlier, but since C++ allows multiple inheritance the issue isn't as much of a problem (so long as they are pure abstract classes with no implementations, if you start mixing code into them then it gets hairier)

like image 87
Erik Funkenbusch Avatar answered Sep 19 '22 01:09

Erik Funkenbusch