473,395 Members | 1,452 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 5234
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Vishal Gandhi | last post by:
Hi , Please help me by advising an real life scenario where Abstract Classes should be used over Interfaces or vice versa . Whats the basic difference between Abstract Class and interface other...
4
by: Tony Johansson | last post by:
Hello! Assume you have an abstract class called Body and a derived class called cylinder. When you have an abstract class you can't instansiate an object. As you can see in the abstract class...
4
by: WittyGuy | last post by:
Hi all, Though I know the concepts of both abstract class & virtual function (like derived class pointer pointing to base class...then calling the function with the pointer...), what is the real...
8
by: Dev | last post by:
Hello, Why an Abstract Base Class cannot be instantiated ? Does anybody know of the object construction internals ? What is the missing information that prevents the construction ? TIA....
12
by: Daedalus.OS | last post by:
Ok first I'm pretty new to OOP, so my question may sound stupid to some of you. If the only answer you can provide is "get a book about OOP" then don't loose your time and mine cause it's already...
0
by: emin.shopper | last post by:
I had a need recently to check if my subclasses properly implemented the desired interface and wished that I could use something like an abstract base class in python. After reading up on metaclass...
17
by: Jess | last post by:
Hello, If I have a class that has virtual but non-pure declarations, like class A{ virtual void f(); }; Then is A still an abstract class? Do I have to have "virtual void f() = 0;"...
6
by: Jeff Louie | last post by:
Owen... Hopefully this is a succinct answer to your question Why can't a static method be abstract or virtual (overridden)?: It is an error to declare a static method abstract or virtual. ...
21
by: Mr.SpOOn | last post by:
Hi, I'm going to work on a project to represent some musical theory in Python, in an object oriented way. I have to manage many elements of music such as notes, intervals, scales, chords and so...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.