Re: GOF Interface Problem

From: Mitchell (cheeliang__at__iname_._com)
Date: 05/29/04


Date: Sat, 29 May 2004 11:01:43 +0800

On 19 May 2004 11:20:16 -0700, merlin2769@hotmail.com (Merlin) wrote:

>Am I right to say that Image(or Graphic) would be another class that
>should inherit from Glyph in order to follow from Fig 2.2 and Fig 2.3
>on the previous page.

Anyway, this is OT. You might wish to try comp.object for more ideas.
I have helped to cross post to comp.object.

For example, page 38 says

"We can treat text and graphics uniformly with respect to how they are
drawn, formatted, and embedded within each other."

Page Page 36 says

"we should treat text and graphics uniformly"
"lets the user embed text within graphics freely and vice versa"

So yeah, I understand Image/Graphic as derived from Glyph.

>Secondly, why does Glyph have Insert() operation in its interface if
>only some of the classes that inherit from it need this operation. The
>interface for Glyph should be all the operations common to the classes
>that derive from it. I have come across the ISP priciple by Robert C.
>Martin that says this is a bad thing and designers should segregate
>the interface and use multiple inheritance. The Glyph interface has
>been polluted by Insert()...

"lets the user embed text within graphics freely and vice versa"

So I understand they were planning to let you embed graphics in text,
thus the text glyphs (character, etc) will need the Insert method.

Also, since it is a hierarchy of classes, with only the classes at the
bottom of the hierachy being non-decomposable/not made up of other
glyphs, it makes sense to let classes all inherit from a base class
Glyph. Otherwise, different classes in the hierachy will need to
inherit from multiple different classes (so as to include and exclude
certain interfaces like Insert), creating a rather messy hierachy.

Cheers



Relevant Pages

  • Re: GOF Interface Problem
    ... "We can treat text and graphics uniformly with respect to how they are ... I understand Image/Graphic as derived from Glyph. ... >only some of the classes that inherit from it need this operation. ... >the interface and use multiple inheritance. ...
    (comp.lang.cpp)
  • Re: GOF Interface Problem
    ... >"We can treat text and graphics uniformly with respect to how they are ... I understand Image/Graphic as derived from Glyph. ... >>only some of the classes that inherit from it need this operation. ... >>interface for Glyph should be all the operations common to the classes ...
    (comp.lang.cpp)
  • Re: GOF Interface Problem
    ... >"We can treat text and graphics uniformly with respect to how they are ... I understand Image/Graphic as derived from Glyph. ... >>only some of the classes that inherit from it need this operation. ... >>interface for Glyph should be all the operations common to the classes ...
    (comp.object)
  • Re: Class with method that returns different pointer depending on implementation?
    ... >> I've got a problem where I want to have an interface to a Graphics ... I might implement Graphics with the SDL ... and any other surface you can think of should inherit ... SURFACE interface, and I can't define SDL_surface myself. ...
    (comp.lang.cpp)
  • GOF Interface Problem
    ... class diagram showing the Glyph hierarchy. ... only some of the classes that inherit from it need this operation. ... interface for Glyph should be all the operations common to the classes ...
    (comp.lang.cpp)