struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Malik Recoing" <m.reco...@almerys.com>
Subject Re: one desing question, Revisited
Date Mon, 03 Feb 2003 09:25:18 GMT
Friday, January 31, 2003 5:31 PM , Cory Newey <cnewey@novell.com> a
écrit :
> I don't understand your response.  The code I propose below does in
> fact use delegation to factorize the functions.

I'm ok with that.

> However, by
> utilizing an interface, all code that works with MyAction and
> MyDispatchAction objects now has a contract that says that both
> objects support the CommonFunction methods.  Thus that code can deal
> with both objects as CommonFunction objects if it wants to.

I was just pointing out is that probably no client code will use the
CommonFunction interface of MyAction and the MyDispatchAction but themselve
so it's maybe not usefull to implement it. And even if a client need
CommonFunction why should they use a MyAction or MyDispatchAction instance
rather than a CommonFunctionImpl instance ?

If there is a need for a contract here, it's also a contract for a behavior
not just for an interface. When you multi-inherite you take the interface
and the behavior of each parent classes. It's not garanteed here for the
clients of CommonFunction interface that they will have the behavior of
CommonFounctionImpl. If you implement a function of CommonFonction another
way than delgating to CommonFunctionImpl nothing will warn you about. So it
is not quite like if you extends Action and CommonFunctionImpl.

Java does not support multiple inhereteance and so there is *no way* to
replace it exactly. This said, and Ashish warned, your code is very clean, I
have nothing about that.

>  This is
> what I understood that Ashish wanted to do.  IOW, what's your beef?
>
> --Cory
>
> > > > m.recoing@almerys.com 01/31/03 09:17AM >>>
> I don't agree with the interface solution. As the name sugest
> CommonFunction
> seems to be only factorization of code and not a real type. MyAction
> and
> MyDispatchAction will never be called from outside as some
> 'CommonFunction'.
> Interfaces are meant to be externals contracts not a way to replace
> inheritance.
>
> IMHO when you want to factorize functions in sevral Classes of
> different
> types you only need to delegate. But maybe I missunderstood what
> Ashish
> whant.
>
> Malik.
>
>
> Friday, January 31, 2003 4:55 PM , Cory Newey <cnewey@novell.com> a
> écrit :
> > Yeah, if you read his entire post, he says that he knows that
> > multiple inheritance isn't allowed in Java.  It looks to me like
> > you'll have to make CommonFunctions an interface.  If the methods
> > in CommonFunctions actually are identical for both MyAction and
> > MyDispatchAction, you could avoid having duplicate code in the two
> > classes by deligating to a third object that actually implements
> > the methods.  What you would end up with would look something like
> > this:
> >
> > MyAction extends Action implements CommonFunctions {
> >    private CommonFunctionsImpl common = new CommonFunctionsImpl();
> >    ... methods in CommonFunctions interface that just call the
> >         common object above to the real work ...
> > }
> >
> > MyDispatchAction extends DispatchAction implements CommonFunctions {
> >    private CommonFunctionsImpl common = new CommonFunctionsImpl();
> >    ... methods in CommonFunctions interface that just call the
> >         common object above to the real work ...
> > }
> >
> > CommonFunctionsImpl implements CommonFunctions {
> >    ... methods that do the real work ...
> > }
> >
> > --Cory
> >
> > Cory R. Newey
> > cnewey@novell.com
> > Senior Software Engineer
> > Novell, the leading provider of Net services software
> >
> >
> > > > > hookomjj@uwec.edu 01/31/03 08:41AM >>>
> > I'm going to save you from getting flamed.... java does not allow
> > multiple
> > inheritance.  You can only extend from a single Object.
> >
> > -Jacob
> >
> > > -----Original Message-----
> > > From: Ashish Kulkarni [mailto:kulkarni_ash1312@yahoo.com]
> > > Sent: Friday, January 31, 2003 9:34 AM
> > > To: struts-user@jakarta.apache.org
> > > Subject: one desing question, Revisited
> > >
> > > Hi,
> > >
> > > When i was thinking about my problem, I think what i
> > > want to do in multiple inhereteance
> > > I want to define a class called CommonFunctions , this
> > > call will have methods which are common, (As name
> > > suggest)
> > > now i have to do some thing like
> > > public class MyAction extends Action, CommonFuntions
> > >
> > > and public class MyDisptachAction extends
> > > DispatchAction, CommonFuntions
> > >
> > > By doing this i will be able to access all the methods
> > > in the class which sybclasses MyAction or
> > > MyDispatchAction
> > > I know the code above is not possible to do, but i
> > > want to do some thing like that..
> > > So what are the ways of achieving it
> > >
> > > =====
> > > A$HI$H
> > >
> > > __________________________________________________
> > > Do you Yahoo!?
> > > Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
> > > http://mailplus.yahoo.com
> > >
> > >
> > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail:
> > > struts-user-help@jakarta.apache.org
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message