On Fri, 22 Mar 2024 at 08:47, Florian Schmaus <flo(a)geekplace.eu> wrote:
For example, assume a XMPP library written in an
object-oriented
language. There is a superclass TopLevelStreamElement which has one
obvious subclass named Stanza. Now, how should we name the other
subclass? TopLevelElementThatIsNotAStanza? Feels ridiculous.
Well, now, that's a really interesting question that delves into OOP design.
So, if you're of the classical Java bent, and therefore like injecting
class hierarchies into everything, you'd have (and I write this in C++,
because, well, reasons):
class TopLevelElement;
class Stanza public TopLevelElement;
class Message public Stanza;
class Presence public Stanza;
OK, so this seems fair - Messages and Presences are both Stanzas, which is
a TLE. Great! So what about a stream:features element?
class Features public TopLevelElement;
Well, it's a TLE, but it's not a Stanza.
The thing is, Messages, Presences, and IQs all have common behaviour which
is sensibly encapsulated into a Stanza class (if we're doing classical OOP,
anyway).
But there's no common behaviour between Features and, say, a '198 ack -
there's nothing that is needed there.
Now, you might want to do polymorphism based on something that's not a
Stanza - I can't actually think why - and for that you might want to inject
an artificial class. But this is an implementation detail, not something to
foist upon the entire community.
Dave.