Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What does this mean?

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"A useful constraint is to say that any instance of the superclass must be an instance of one of the subtypes of a group.(The superclass is then abstract)."

The above is from UML distilled. Can someone explain me with example(preferably) what exactly this means??
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How would you make an instance of an abstract class, when its concrete subclasses are present OR subclasses of one or more subclasses are present OR ...... so forth?

Of course by making an instance of any concrete class that belongs to that group. I hope, you would get the notion.
[ May 17, 2007: Message edited by: Adeel Ansari ]
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They're saying "instance of the superclass" and "abstract superclass" in the same sentence. That's not something I'd ever say, because for me as a Java-head "abstract class" means you can never have an instance. The whole thing boils down to "abstract types good".

To use more words and probably shed little more light, I might have said: Any object instance that can be assigned to a variable of the supertype must be an instance of a subtype, not an instance of the supertype.

For example, you cannot say

But you can say

This follows the suggested constraint: any object you can assign to a variable of type List is an instance of some subtype, never an instance of List.
[ May 17, 2007: Message edited by: Stan James ]
 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An instance of a subtype is an instance of the supertype.

"Let q(x) be a property provable about objects x of type T. Then q(y) should be true for objects y of type S where S is a subtype of T." - Liskov substitution principle.

I'll let q(x) be that objects x are of type T. Then q(y) means that objects y are also of type T.

Having one class abstract is just an implementation detail, it doesn't change the concept.
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Tontang Bei:
The above is from UML distilled.



Which edition are you referring to?

He was most likely referring to the {complete} generalization set constraint.

Martin Fowler has updated his statement regarding the {complete} generalization set constraint (UML 2.0; in UML 1.x this was called a discriminator constraint) in the latest (3rd) edition (Changes in UML Versions):


Complete and Incomplete Discriminator Constraints
On page 78 of previous printings of UML Distilled, I said that the {complete} constraint on a generalization indicated that all instances of the supertype must also be an instance of a subtype within that partition. UML 1.1 defines instead that {complete} indicates that all subtypes within that partition have been specified, which is not quite the same thing. I have found a lot of inconsistency on the interpretation of this constraint, so you should be wary of it. If you do want to indicate that all instances of the supertype should be an instance of one of the subtypes, then I suggest using another constraint to avoid confusion. Currently, I am using {mandatory}.



According to UML 2.0 a generalization set constraint can be disjoint, overlapping, complete or incomplete.

Have a look at figure 9 of UML 2 Class Diagrams.

:gender is an identified generalization set. A Person must be Male or Female; the instance cannot be a Person while being neither Male or Female, and a Person can only be either Male or Female, not both. Also there cannot be another subtype in the :gender generalization set (for the purposes of this model). Therefore the :gender generalization set has the constraint {disjoint,complete}. :role is another identified generalization set. This time it is conceivable that a Person can be an Employee and a Student at the same time. So the constraint would be at least {overlapping}. If the :role generalization set has other specializations (i.e. in addition to Student and Employee) not shown in this model then you could expand to a {overlapping,incomplete} constraint.
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

An instance of a subtype is an instance of the supertype.



I'll defer to those who have studied UML more recently than I, but in the context of Java, I'd never say that.
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Stan James:
I'd never say that.



...because you don't indulge in tautologies...
 
Ricky Clarkson
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stan, instanceof also disagrees with you. Between instanceof, me and Barbara Liskov, you're on the ropes.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Stan James:

I'll defer to those who have studied UML more recently than I, but in the context of Java, I'd never say that.



It's still true - not only in Java or UML, but in general by definition, as far as I can tell.

You should also be carefull to not confuse types with classes - not all classes coming with the JDK follow LSP; java.sql.Date actually is *not* a subtype of java.util.Date, although it's a sub*class*.
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The instanceof operator doesn't say an object is an instance of anything. It says At run time, the result of the instanceof operator is true if the value of the RelationalExpression is not null and the reference could be cast (�15.16) to the ReferenceType without raising a ClassCastException. Otherwise the result is false.

LSP doesn't add much ... Let q(x) be a property provable about objects x of type T. Then q(y) should be true for objects y of type S where S is a subtype of T. Objects x of abstract type T can't exist in the absence of any subtypes so it's impossible to prove any properties about them separate from S.

I think you suggest an instance of any subtype is also an instance of every supertype in the hierarchy. I can accept that for one point of view, that fancy book learnin. I think I'm suggesting an object is an instance of exactly one type. Is that flat wrong or is it looking at something different?
[ May 22, 2007: Message edited by: Stan James ]
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Unified Modeling Language Reference Manual 2e (2004) (amazon US) p.326:


direct class
The class that most completely describes an object.
...
Semantics
An object may be an instance of many classes - if it is an instance of a class, then it is also an instance of the ancestors of the class. The direct class is the most specific description of an object, the one that completely describes it. An object is a direct instance of its direct class and an indirect instance of the ancestors of the direct class. An object is not an instance of any descendants of the direct class (by definition).
...

 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, now I give up.
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Stan James:
I think I'm suggesting an object is an instance of exactly one type. Is that flat wrong or is it looking at something different?



It is using the term "type" in a way that is not common usage in our profession.
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess I'm exposing some deep seam of ignorance, but follow that up ...

I would have used "class" instead of "type" but those primitives get in the way.
[ May 28, 2007: Message edited by: Stan James ]
 
My cellmate was this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic