Book a Demo

Author Topic: Showing inherited and implemented methods  (Read 16693 times)

Thomas Mercer-Hursh

  • EA User
  • **
  • Posts: 386
  • Karma: +0/-0
  • Computing Integrity
    • View Profile
Showing inherited and implemented methods
« on: June 07, 2010, 04:43:57 am »
I'm wondering about what is considered good practice in the following scenario.

Given two interfaces I1 and I2.  Logically, if the language permitted it, I would structure these as I2 inheriting from I1, but the language in question does not currently support interface inheritance.

There are one or more concrete classes C1, C2, etc.  Each is an implementation variant with different performance and other distinguishing features, but with the same signature.  This signature is defined by I1 and I2.  If I had interface inheritance, I would say that C1 implements I2, but without that language feature, I have a choice of either saying the C1 implements I1 *and* I2 or doing what I describe next.

Since C1, C2, etc. can be substituted for each other, we want a common reference to use in places where any of them can be used.  With interface inheritance, that would be I2 since it would imply all of the methods of both.  Without interface inheritance, what we are doing is to define an abstract class A which implements I1 and I2 and then C1, C2, etc inherit from A.  Thus, A can be used as the type of a parameter and any of C1, C2, etc. can be used.

My question is this.  Normally, if a class inherits from another class or implements an interface, I would not show the properties and methods from the parent class or interface in the class unless they overrode the implementation in the parent.  Here, however, the situation is a bit different since the method definitions in A are abstract, not actual implementations of the methods in I1 and I2.  Similarly, the methods in C1, and C2 are where the actual implementation is provided.  All that is being inherited from the abstract class is the signature of the method.  So, there is a change in type in both cases which doesn't exist in the simpler cases.

In such a situation, where should the methods appear in a class diagram?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Showing inherited and implemented methods
« Reply #1 on: June 07, 2010, 04:04:00 pm »
Thomas,

I would show the operations only on the classes that actually implement the operation. (or in some way redefine it by altering things like visibility or constraints)

Geert

Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: Showing inherited and implemented methods
« Reply #2 on: June 07, 2010, 06:38:47 pm »
I would also just show the operations that are actually implemented by the classes.
BTW: i don't think it's good practice to inherit anything on interface level (I2 inherits I1), keep your interfaces as narrow as possible, and use multiple inheritance for them on implementation class level. At least for interfaces multiple inheritance should be provided by the programming language (sure that it's like this for C++ and C#, guess java allows that as well).

HTH
g.

beginner

  • Guest
Re: Showing inherited and implemented methods
« Reply #3 on: June 07, 2010, 07:45:15 pm »
It looks like the language in question is COBOL (or the like). When implementing interfaces in such kind of language you would usually make use of COPY (or Include) statements. So each of your classes may implement (COPYing) any interface needed and implement it as desired.

b.

Thomas Mercer-Hursh

  • EA User
  • **
  • Posts: 386
  • Karma: +0/-0
  • Computing Integrity
    • View Profile
Re: Showing inherited and implemented methods
« Reply #4 on: June 08, 2010, 02:53:25 am »
@Geert .... only on the one that implements?  Then there would be nothing listed in the interface at all!

@Makulik, the prototype for the current work is the Java collection class hierarchy in which Iterable is a superinterface for the Collection interface.  This seems perfectly reasonable to me since things other than collections can be iterable and all collections are iterable.  If there were no need for a generalization hierarchy below the top level, I would be content for the top level to just implement the two separate interface, but if I want a parameter, for example, to be any kind of collection, then I can't point to the collection interface alone since, without that superinterface, it wouldn't be iterable.

@beginner, No, not COBOL.  I think I wrote my last COBOL around 1975!  The language is ABL or Advanced Business Language, formerly known as the Progress 4GL ... of which there are multiple billions of lines of unique code in production world wide.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Showing inherited and implemented methods
« Reply #5 on: June 08, 2010, 01:38:31 pm »
Quote
@Geert .... only on the one that implements?  Then there would be nothing listed in the interface at all!

Allright, you got me there ;)
What I should have said is: Define operation only on those elements that define, redefine or implement the operation.

Happy now :D

Geert

beginner

  • Guest
Re: Showing inherited and implemented methods
« Reply #6 on: June 08, 2010, 05:36:18 pm »
I guess the promises of COBOL and 4G languages were merely the same. There's actually no big difference between both.

b.

Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: Showing inherited and implemented methods
« Reply #7 on: June 08, 2010, 06:21:47 pm »
COBOL is way off more blithering and has (had?) some stoopid text layouting rules for the code IIRC. had it in school, never needed to practice  ;D ...

beginner

  • Guest
Re: Showing inherited and implemented methods
« Reply #8 on: June 08, 2010, 06:44:51 pm »
More than 25 years ago I had lectures in SW engineering (Prof. Christiane Floyd). She told us to solve the interface problems using COBOL - because this would be the most difficult way. And she was right. I learned a lot and still make use of the knowledge gained in these lectures.

I also worked with a 4GL (Natural) years later. Like COBOL the 4GL do not care about interfaces. Now people like Thomas have to cope with the heritage. Hercules' work at Augias' stable was easier...

b.
« Last Edit: June 08, 2010, 06:45:36 pm by beginner »

sargasso

  • EA Practitioner
  • ***
  • Posts: 1406
  • Karma: +1/-2
  • 10 COMFROM 30; 20 HALT; 30 ONSUB(50,90,10)
    • View Profile
Re: Showing inherited and implemented methods
« Reply #9 on: June 08, 2010, 08:07:10 pm »
Just don't forget. COBOL was the first OO language, both the data and the processes were described in the same construct.  

But my thoughts and best wishes do go out to Thomas, I first encountered "ProGress" (read "ReGress") some years ago, it never worked then and I severely doubt that a name change fixed a great deal.  Some "4GL's" were really just never meant to be.

But getting back to the OP, aka Thomas, remember the system designer's rules 1 and 2.
1) If it is not feasible then kill the project manager
2) repeat 1) until project is feasible, i.e it can come reasonably close to solving a reasonable subset of the clients needs withing a reasonable economic model (i.e. "I" get "richer" subsetted by "I" am not getting involved in the "politics")

These two rules have served me well over the last 35 years or so, or as some certain "beginners" may believe, the last 35million years or so.

lak
bruce
"It is not so expressed, but what of that?
'Twere good you do so much for charity."

Oh I forgot, we aren't doing him are we.

beginner

  • Guest
Re: Showing inherited and implemented methods
« Reply #10 on: June 09, 2010, 01:11:14 am »
"beginner" in the meaning of "beginning to petrify". Just a way to pretend I'm not from Jurassic Park

b.

Thomas Mercer-Hursh

  • EA User
  • **
  • Posts: 386
  • Karma: +0/-0
  • Computing Integrity
    • View Profile
Re: Showing inherited and implemented methods
« Reply #11 on: June 09, 2010, 02:39:02 am »
@Geert: "Define operation only on those elements that define, redefine or implement the operation."

So, would I interpret this to mean that the operation would be shown on all three since the interface defines it as a simple operation, the abstract class "implements" it as an abstract operation and the concrete class actually implements it?

@Everybody:  Actually, ABL is not even vaguely related to COBOL.  In the course of my career I have probably written a quarter million lines of COBOL, albeit a long time ago and a couple of million lines of ABL.  ABL was the only 4GL back in the 80s, when 4GLs were trendy, in which one could genuinely write the entire application in the 4GL instead of having to write 10-20% in C.  There are billions of lines of it in production with many millions of users and a couple thousand VARs who earn their living with it.  It has some ugly and annoying bits, but especially now that it has a pretty good OO structure, it is really a pretty nice language to write in ... at least if your priority is being able to get the job done and maintain what you have written, rather than showing how clever you can be.

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: Showing inherited and implemented methods
« Reply #12 on: June 09, 2010, 09:59:31 am »
Quote
@Geert: "Define operation only on those elements that define, redefine or implement the operation."

So, would I interpret this to mean that the operation would be shown on all three since the interface defines it as a simple operation, the abstract class "implements" it as an abstract operation and the concrete class actually implements it?
I wouldn't show the operation in the abstract class as it's "just passing through".
The Sparx Team
[email protected]

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Showing inherited and implemented methods
« Reply #13 on: June 11, 2010, 04:29:18 pm »
Quote
@Geert: "Define operation only on those elements that define, redefine or implement the operation."

So, would I interpret this to mean that the operation would be shown on all three since the interface defines it as a simple operation, the abstract class "implements" it as an abstract operation and the concrete class actually implements it?

Thomas,

I would show the abstract operation on the abstract class, since it does nothing at all to it.
The operation was defined abstract (by definition because it was defined on an interface) and the abstract class doesn't change anything to its implemenentation or definition.

I see this the same was as if the operation would be defined abstract on an abstract superclass (generalization) of the abstract class. In that case you wouldn't show it either would you?

When you think about it, interfaces are nothing more then "pure" abstract superclasses, so that's the way I would treat them.

Geert