6.170 Forum
August 16, 2006, 04:52:04 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Welcome to the 6.170 Forum.
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Regarding extension of interfaces Graph into subinterfaces MutableGraph  (Read 631 times)
amcp
Newbie
*
Posts: 9


View Profile
« on: March 06, 2006, 01:47:58 AM »

Hello,
I have an interface Graph and an interface MutableGraph which extends Graph.

I know am writing the implementation of this interface hierarchy,
but I do not know about the consequences of having my class implement the superinterface as opposed to, say, both the super and the sub.

If I implement the sub's interface, will I still be able to cast instances of the class as the superinterface?
Or, to do this, do I need to have the class implement both?

thank you
Logged
Greg Belote
Jr. Member
**
Posts: 16


View Profile Email
« Reply #1 on: March 06, 2006, 03:06:09 AM »

For anything that implements the subinterface, it is considered an instanceof both the sub and super. So yeah, you can cast it as the super interface.
Logged
C. Scott Ananian (TA)
Administrator
Sr. Member
*****
Posts: 126


View Profile WWW Email
« Reply #2 on: March 08, 2006, 06:50:40 PM »

Be aware that you should be disciplined in your use of these dual interfaces.  A mutable graph "is a" immutable graph, which may surprise some users -- especially if you pass an "immutable" graph to some code and then start changing it (via it's mutable subclass).

This is a reasonable design decision, but be sure to carefully document the gotchas.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1 RC2 | SMF © 2001-2005, Lewis Media Valid XHTML 1.0! Valid CSS!