[kepler-dev] Duplicate Vergil classes

Edward A. Lee eal at eecs.berkeley.edu
Sat Jun 4 10:49:47 PDT 2005


In theory, it should never be necessary to copy a class and modify
it.  If it can't be subclassed (e.g. the key variable private) then
it should be refactored and then subclassed (e.g. protected accessor methods
for the private variables should be added).  A common design pattern
used in Ptolemy is the "strategy pattern" where a base class does
something like this:

    public void bigComplexMethod() {
        ... lots of stuff ...
        doSomething();
        ... lots more stuff ...
   }
   protected void doSomething() {
       // Base class does nothing
   }

The protected method provides a placeholder for the subclass to
do something...

Edward


At 09:57 AM 6/3/2005 -0700, Shawn Bowers wrote:
>Edward A. Lee wrote:
>>Shawn:
>>The risk here is that if we change IOPortController (which is likely),
>>Kepler will not see the change.  At a minimum, this means new features
>>would not be there.  At a maximum, the Kepler build will break...
>>We really need to be using object-oriented design here...
>>Wouldn't it make more sense to subclass?
>
>Well, maybe you could elaborate how that would work exactly. Seems like at 
>some point we would have to rewrite/copy one of the ptolemy classes. 
>Unless of course, there was some way to specify which class to use via a 
>config file (which is done, e.g., in the File > New, but not in other 
>places, right?)  Or are we missing something more fundamental?
>
>shawn
>
>
>
>
>>Edward
>>At 02:19 PM 6/2/2005 -0700, Shawn Bowers wrote:
>>
>>>Hi Christopher,
>>>
>>>Basically, all I wanted to do was to add a menu item (for the time being
>>>...) to the right-click menu on ports. I also did the same for actors.
>>>
>>>I agree that having duplicated code is a bad idea.
>>>
>>>Right now, though, I don't have time to extend ptolemy to make this more
>>>configurable. Also, the use of right click menus for what I am adding
>>>may not be the final "entry point" into the additions I'm trying to make
>>>-- so until that is finalized, I just started "hacking" to get it up and
>>>running for now ;-)
>>>
>>>I think that we (speaking for the "kepler" project) need ourselves to
>>>figure out what GUI extensions we ultimately want and then come up with
>>>a plan for how to achieve these extensions, including any mechanisms for
>>>making Vergil more extensible/customizable. Right now, I think we are
>>>still in the "experimental" and "fleshing it out" stage.
>>>
>>>Generally speaking, I think making all right-click menus customizable
>>>would help a lot ... but that might be a lot of work.
>>>
>>>Thanks,
>>>shawn
>>>
>>>
>>>
>>>
>>>Christopher Brooks wrote:
>>> > Hi Shawn,
>>> >
>>> > Is there anyway we can modify the parent class in the Ptolemy II cvs
>>> > repository so that you extend ptolemy.vergil.actor.IOPortController
>>> > instead of doing a wholesale copy of the class?
>>> >
>>> > If you don't yet have write access to the Ptolemy II cvs repository,
>>> > I'm more than willing to give it to you so you could add extension
>>> > points to Ptolemy II.
>>> >
>>> > The reason is that we have gotten in to quite a bit of trouble
>>> > maintenance-wise when we have duplicated code.  The JNI and Single
>>> > Window code from Thales caused Edward no end of grief when
>>> > he went to update the copied base classes.
>>> >
>>> > Anyway, the up shot is that I'm more than willing to help out
>>> > if we can avoid duplicate code.
>>> >
>>> > _Christopher
>>>_______________________________________________
>>>Kepler-dev mailing list
>>>Kepler-dev at ecoinformatics.org
>>>http://mercury.nceas.ucsb.edu/ecoinformatics/mailman/listinfo/kepler-dev
>>
>>------------
>>Edward A. Lee
>>Professor, Chair of the EE Division, Associate Chair of EECS
>>231 Cory Hall, UC Berkeley, Berkeley, CA 94720
>>phone: 510-642-0253 or 510-642-0455, fax: 510-642-2845
>>eal at eecs.Berkeley.EDU, http://ptolemy.eecs.berkeley.edu/~eal

------------
Edward A. Lee
Professor, Chair of the EE Division, Associate Chair of EECS
231 Cory Hall, UC Berkeley, Berkeley, CA 94720
phone: 510-642-0253 or 510-642-0455, fax: 510-642-2845
eal at eecs.Berkeley.EDU, http://ptolemy.eecs.berkeley.edu/~eal  



More information about the Kepler-dev mailing list