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!