470,833 Members | 1,410 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

abstract class and instantiation

I am not sure why, in the RefinedAbstraction class, that the abstract
baseclass' constructor can be called. I have always thought that abstract
classes cannot be instantiated. It is a little confusing. Would it be better
programming practice to simply assign imp to this. imp in the subclass?

thanks, Mike

abstract class Abstraction{

protected Implementor imp;

public Abstraction(Implementor imp){

this.imp = imp;
}

abstract void operation();
}
class RefinedAbstraction extends Abstraction{

public RefinedAbstraction(Implementor imp){

super(imp); //not sure how this can work.
}

public void operation(){

imp.operationImp();
}
}



----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Jul 17 '05 #1
1 5121
On Sat, 23 Oct 2004 09:58:42 -0600, "Michael G" <mi****@montana.com>
wrote:
I am not sure why, in the RefinedAbstraction class, that the abstract
baseclass' constructor can be called. I have always thought that abstract
classes cannot be instantiated. It is a little confusing. Would it be better
programming practice to simply assign imp to this. imp in the subclass?

thanks, Mike

abstract class Abstraction{

protected Implementor imp;

public Abstraction(Implementor imp){

this.imp = imp;
}

abstract void operation();
}
class RefinedAbstraction extends Abstraction{

public RefinedAbstraction(Implementor imp){

super(imp); //not sure how this can work.
}

public void operation(){

imp.operationImp();
}
}



----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---

Don't know where you got the code from. It looks like some sort of
bridge pattern but something is wrong in my opinion.
The Abstraction class should look like this:

abstract class Abstraction {
protected Implementor implementor;

public void setImplementor(Implementor implementor) {
this.implementor = implementor;
}

abstract public void operation();
}

Then you would have an Implementor interface and a class that realizes
it like this:

public class ConcreteImplementor implements Implementor {
public void operation() {
System.out.println("My operation");
}
}

A test class could be as follows:

public class Client {
public static void main(String[] args) {
Abstraction abstraction = new RefinedAbstraction();
abstraction.setImplementor(new ConcreteImplementor());
abstraction.operation();
}
}
Hopes this helps to understand that you do NOT instantiate in a bridge
pattern, you use inheritence!
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Vishal Gandhi | last post: by
4 posts views Thread by Tony Johansson | last post: by
12 posts views Thread by Daedalus.OS | last post: by
reply views Thread by emin.shopper | last post: by
21 posts views Thread by Mr.SpOOn | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.