On Tue, Apr 26, 2011 at 8:11 PM, RoqueManuel <[email protected]> wrote:

> That's right dear James but, I found some situations where I can be
> nice that you could have multi inheritance like this (http://
> www.javaworld.com/javaworld/jw-10-2005/jw-1024-multiple.html). Also I
> want to accomplish this solution in a hypotetical way. I want to know
> what to do if that happend, and do it the best way.
>
> On 24 abr, 20:16, James Fraser <[email protected]> wrote:
> > To be honest, you should never really need multiple inheritance. If you
> find
> > yourself needing to extend multiple types you may need to rethink your
> > design.
> >
> >
> >
> >
> >
> >
> >
> > On Sun, Apr 24, 2011 at 6:46 PM, RoqueManuel <[email protected]> wrote:
> > > Hello guys,
> >
> > > I'm facing a problem
> > > I need to solve a problem of multi inherence using inner classes.
> >
> > > So the problem is this.
> >
> > > I have a Father class and also a Mother class and I need that the
> > > class Son extends from both Father and Mother so Son class can respond
> > > to class to Father Interface and also Mother Interface. So I did the
> > > next code.  (What I usually did).
> >
> > > class Father{
> > >        void m(){
> > >                System.out.println("m()");
> > >        }
> > > }
> >
> > > interface Mother{
> > >        void n();
> > > }
> >
> > > class Son extends Father implements Mother{
> > >        public void n(){
> > >                System.out.println("n()");
> > >        }
> > > }
> >
> > > So we need to implement the solution using a inner class. And we did
> > > something like this.
> >
> > > class Father{
> > >        void m(){
> > >                System.out.println("m()");
> > >        }
> > > }
> >
> > > class Mother{
> > >        public void n(){
> > >                System.out.println("n()");
> > >        }
> >
> > >        class Son extends Father {
> > >                void n(){ // Metodo wraper se llama igual e invoca a
> otro
> > > metodo que
> > > se llama igual.
> > >                        Mother.this.n();
> > >                }
> > >        }
> >
> > >        public static void main(String[] args) {
> > >                Mother.Son hijo = new Mother().new Son ();
> > >                hijo.m();
> > >                hijo.n();
> > >        }
> >
> > > }
> >
> > > This approach is better according to what our teacher explain. And
> > > this solution can be use with more than two classes.
> >
> > > And I did this.
> >
> > > class Human{
> > >        void m(){
> > >                System.out.println("m()");
> > >        }
> > > }
> >
> > > class Dead{
> > >        void n(){
> > >                System.out.println("n()");
> > >        }
> >
> > >        class InnerDeath extends Human{
> > >                void n(){
> > >                        Dead.this.n();
> > >                }
> > >        }
> > > }
> >
> > > public class Vampire {
> > >        void o(){
> > >                System.out.println("o()");
> > >        }
> >
> > >        class Dracula extends Dead.InnerDeath{
> > >                Dracula(){
> > >                        new Dead().super();
> > >                }
> >
> > >                void o(){
> > >                        Vampire.this.o();
> > >                }
> > >        }
> >
> > >        public static void main(String[] args){
> > >                Vampire.Dracula dracula = new Vampire().new Dracula();
> > >                dracula.m();
> > >                dracula.n();
> > >                dracula.o();
> > >        }
> > > }
> >
> > > So what I have is that, I use two inner classes one that extends from
> > > Humand and can acces to Dead attributes and methods, And It's from
> > > this class that extends Dracula and so that Dracula is the result and
> > > can respond to all calls to methods of the other classes.
> >
> > > Is this the best approach? Do you know a better way to acomplish the
> > > expected result?
> > > I also have another posible solutions to accomplish this problem. I
> > > hope that someone can comment about it. What I want is to have a
> > > solution like a pattern to problems of what I should do if I need two
> > > class (I already have that: inherence plus inner class) three, four,
> > > five and so on.
> >
> > > Thanks in advance.
> >
> > > Roque Rueda.
> >
> > > --
> > > To post to this group, send email to
> > > [email protected]
>
Dear Roque And to all the friends.

Multiple inheritance was considered too difficult to maintain, either for
the designers of Java, (also JavaScript) and the most important to all ADA.
Multiple inheritance is supported by C which is more a system language  than
a programming language. If you envisage to use multiple inheritance in your
designs, you will rapidly fall in difficulty for following which fields
comes from when and sooner the code gets some sort of enigma that will be
better leave than to try to debug. Also you will find yourself in difficulty
when using external databases with the fields in multiple inheritance. Clear
and understandable code is essential. Programming languages may define very
deep procedures but it will be worth first try and master in normal, clean,
understandable and the inevitable result of these the efficient code.
Bedri Doğan Emir

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en

Reply via email to