Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #540

Re: Instantiate an abstract class

From Rob McDonald <rob.a.mcdonald@gmail.com>
Newsgroups comp.lang.java.help
Subject Re: Instantiate an abstract class
Date 2011-04-05 14:49 -0700
Organization http://groups.google.com
Message-ID <d49fb9bf-d0a1-409e-9fda-d04cc2c0e115@1g2000yqq.googlegroups.com> (permalink)
References <61c7300d-6011-4639-a5f1-5cd4c58906fa@r4g2000prm.googlegroups.com> <5Z-dnerIwYsWFgbQnZ2dnUVZ_qydnZ2d@earthlink.com>

Show all headers | View raw


On Apr 5, 5:37 pm, Patricia Shanahan <p...@acm.org> wrote:
> On 4/5/2011 2:14 PM, Rob McDonald wrote:> Now, we all know that you can't instantiate an abstract class -- but I
> > want to anyway...  Actually, I would like my abstract class to be able
> > to instantiate another instance of whatever concrete class it is at
> > the time.
>
> ...
>
> Have you tried making AFoo Cloneable, and giving it a clone method? Your
> requirements seem to match the normal clone() behavior.
>
> Patricia

Thanks Patricia,

My understanding of clone() is that it constructs a duplicate instance
of your object -- all fields would have identical values.  I don't
want a duplicate, I'd like a new fresh one.

This class previously was not abstract (and everything worked fine),
but now I would like to create two slightly different versions.  So, I
would like to leave the common implementation matters in the abstract
class, and only implement the differences.

I'm not sure if more information will help or confuse things, but here
goes...
(I realize that a through redesign may be appropriate here, but I
would rather not.  As I said, I got here from code which worked, and I
think there 'ought to be' a way to make this work.)

My object is actually a container with some advanced functionality.
You can think of it as a group of items -- sometimes I want to create
a subgroup of items -- and treat it as an item at the first level.

Initially:

Group G1
 contains items a,b,c,d,e,f

Later:

Group G1
 contains items a,G2,e,f

Group G2
 contains items b,c,d


Where, Group extends the abstract AGroup, and the code we're
discussing is in AGroup.  When AGroup.createSubGroup() goes to make
Group G2, it needs a type to instantiate.

Hope this clarifies; thanks for the help,

Rob

Back to comp.lang.java.help | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Instantiate an abstract class Rob McDonald <rob.a.mcdonald@gmail.com> - 2011-04-05 14:14 -0700
  Re: Instantiate an abstract class Patricia Shanahan <pats@acm.org> - 2011-04-05 14:37 -0700
    Re: Instantiate an abstract class Rob McDonald <rob.a.mcdonald@gmail.com> - 2011-04-05 14:49 -0700
  Re: Instantiate an abstract class Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-04-05 17:48 -0400
    Re: Instantiate an abstract class Rob McDonald <rob.a.mcdonald@gmail.com> - 2011-04-05 14:54 -0700
      Re: Instantiate an abstract class Patricia Shanahan <pats@acm.org> - 2011-04-05 15:09 -0700
      Re: Instantiate an abstract class Lew <noone@lewscanon.com> - 2011-04-06 12:43 -0400
        Re: Instantiate an abstract class "John B. Matthews" <nospam@nospam.invalid> - 2011-04-06 22:07 -0400
  Re: Instantiate an abstract class Roedy Green <see_website@mindprod.com.invalid> - 2011-04-05 19:02 -0700
  Re: Instantiate an abstract class Roedy Green <see_website@mindprod.com.invalid> - 2011-04-05 19:42 -0700
  Re: Instantiate an abstract class Lothar Kimmeringer <news200709@kimmeringer.de> - 2011-04-06 18:26 +0200
    Re: Instantiate an abstract class Lew <noone@lewscanon.com> - 2011-04-06 12:49 -0400
      Re: Instantiate an abstract class Patricia Shanahan <pats@acm.org> - 2011-04-06 10:09 -0700
      Re: Instantiate an abstract class Lothar Kimmeringer <news200709@kimmeringer.de> - 2011-04-07 01:01 +0200
  Re: Instantiate an abstract class Wojtek <nowhere@a.com> - 2011-04-06 12:41 -0700

csiph-web