By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,260 Members | 1,338 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,260 IT Pros & Developers. It's quick & easy.

GOF Interface Problem

P: n/a
Hi

For any of you that own a copy of GOF book, on page 38 there is a
class diagram showing the Glyph hierarchy. Two questions

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.

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()...

If I am right then how can we resolve the issue without
overcomplicating the design.

Kind Regards

Merlin
Jul 22 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On 19 May 2004 11:20:16 -0700, me********@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
Jul 22 '05 #2

P: n/a
In article <j8********************************@4ax.com>,
Mitchell <cheeliang_@_iname_._com> wrote:
On 19 May 2004 11:20:16 -0700, me********@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.


I don't think this is a good idea. What does it mean to insert a glyph
into, say, a Rectangle, or a Character? Glyph should only have methods
that *all* sub-types can implement (even if it is a null
implementation.) 'Insert' is not such a method.
Jul 22 '05 #3

P: n/a
Daniel T. wrote:
Mitchell wrote:

"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.


I don't think this is a good idea. What does it mean to insert a glyph
into, say, a Rectangle, or a Character? Glyph should only have methods
that *all* sub-types can implement (even if it is a null
implementation.) 'Insert' is not such a method.


Guys, take the GOF book, and take out the "word processor" sample
application. Now put in an application which you thought of. That
application must show every pattern, and use only familiar and accessible
concepts.

The OP has detected a point where the "word processor" sample application
may fall down. There may be more. However, the ultimate arbiter would be the
actual implementation of this hypothetical application.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 22 '05 #4

P: n/a
> Hi

For any of you that own a copy of GOF book, on page 38 there is a
class diagram showing the Glyph hierarchy. Two questions

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.

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()...

If I am right then how can we resolve the issue without
overcomplicating the design.

Kind Regards

Merlin


If I've got the right end of the stick, if you refer to page 166 of
the implementation section for composite it discusses the tradeoffs,
safety v transparency, of declaring Insert in the base component class
or not, GoF "emphasize transparency over safety" in the examples.
Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.