Enumerate multiple inheritance scenarios and their java equivalents?
hi,
ppl have often said things like
"java doesn't support multiple inheritance but this is ok, since there are other mechanisms for doing the same thing (by which we nearly always mean interfaces)"
how solid a statement is this? are there any formal methods available eg smt like "over all possible inheritance trees over all possible classes, only a handful of cases are distinct when viewed from the converting-to-single-inheritance scheme"?
the two things mentioned as harder to workaround are mixins and the diamond problem - are there more?
also what other mechanism apart from interfaces (if any) are useful?
any help appreciated,
asjf
What I say is that it doesn't matter since there is
almost never any need for MI. Most of the time it is
used it is used because the developer/designer did not
understand what they were doing and it should not have
been used in the first place.
That leaves one with very few cases where it should
ever be used. And that coupled with the fact that a
developer should never use it unless they are very
experienced (so that they actually know that it should
be used,) means that practicing programmers should
leave discussion of such usages to scholarly
journals.thanks :) I guess my problem is that often with computer stuff you don't have to rely on other peoples experience about things - you can go and test it yourself
I've done very little C++ development, and so have never come across real-world multiple inheritance. I bumped into the first situation with some java code where it might've been a neat solution recently but this could easily fit into the "designer did not understand what they were doing" category from above..
will have a casual look around the scholarly journals if I can find any that look promising :)
asjf
Similar Messages
-
Is it possible to create a configuration profile that will install multiple network printers and their associated drivers?
I was not able to find profile manager on my employer's installation of 10.6 Server. Is this only a feature of 10.7/10.8 server?10.6 server does not have profile manager, profile manager is only available in 10/7 and 10.8 server
for 10.6 server you'll need to use wgm and server admin
printer management with 10.6, I recommend you read the relevant server manuals regarding
print server and user management, printer management -
Multiple inheritance, delegation and syntactic sugar
Given that delegation of an interface to a class member gives you most of the effect of multiple inheritance, why isn't there any syntactic sugar in the language to make this easy?
For example, you could have:
class B extends A implements I delegate i { I i = new IAdapter(); }
The semantics is simple: for each method in each delegated interface, if there is no method with that signature defined in the class then create one with a body that delegates the call to the given member. If there is an ambiguity from multiple interfaces, just flag it at compile time so that the programmer must add an explicit method.
This doesn't impact the class file format as it isn't doing anything that can't be done longhand in the code. It would even provide some protection from interface changes, as a recompile would pass the problem on to the delegate (which would likely inherit from some standard adapter class which would be modified at the same time as the interface).
Why isn't this done (apart from because MI is inherently evil and just suggesting this addition means I'm a bad person). It would make the language a tiny bit bigger, but at least when people ask why Java doesn't have proper MI you could answer 'it does and you do it like this' with an almost straight face.
JontyThe only problem with this is that with multiple
delegates it kinda falls apart.
When yourFunc() is called on an instance of A, which
function is called?original> If there is an ambiguity from multiple interfaces, just flag it at compile
original> time so that the programmer must add an explicit method.
My suggestion was that if there is any ambiguity then no delegation is made, forcing the programmer to do it manually.
Normally in Java it's no big deal when multiple
interfaces have the same methods in them.Actually, I find it a bit of an odd choice by the language designers allowing same signature functions defined in different interfaces to not generate a name clash. Normally this indicates that there is, or soon will be, a bug. I can't think of any situation where this is good programming - if you want the method to exist in both interfaces then it should be defined in a third and inherited into both. This makes it clear that it really is the same method.
Not saying that delegates are a bad idea, but simple
examples don't prove that delegates are a worthwhile
feature to add.The point is that delegation is a commonly used pattern, and is almost always trotted out as a good way of getting most of multiple inheritance. The comments so far are about the problems with this pattern, not with my suggestion to make it easier to use. -
Alternative for multiple inheritance (AbstractQueue and AbstractList)
Hello all,
What is the best alternative for multiple inheritance? I want to make a list, which supports queue operations. Both AbstractQueue en AbstractList are useful, so I would like to use them both, instead of implementing the methods myself or copying the code.
thanksDo you mean you want a class just like LinkedList?
Why don't you look at the code for LinkedList. Perhaps you could even use it.
Most Queue methods have trivial implmentations using a List.
From the source for LinkedList
public class LinkedList<E>
extends AbstractSequentialList<E>
implements List<E>, Queue<E>, Cloneable, java.io.Serializable -
Multiple account scenario and transaction launcher (CRM7.0)
When I want to get the personnel number transferred from the webclient into R3 via the transaction launcher I can get the current customer copied into R3 from the service ticket. In the multiple account scenario I want to get the BP "involved employee" transferred instead of the current customer being the reporting customer (on behalf of).
Does anyone has the parameter for this?
Thanks,
Donny
Edited by: Donny Mensen on Sep 1, 2009 10:12 AM
Edited by: Donny Mensen on Sep 1, 2009 10:15 AMWrong interpretation of multiple account scenario by user.
-
Hello,
I have been programming Java for last year,
evolved in quite some skills with it, and
really think it is great...
However, I was shocked to find out that there
is no multiple inheritance feature.
I know it is rare, and my case proves it
(1 year now, I never needed it)
HOWEVER, when one needs multiple inheritance,
then they really do need it.
I have interfaces which I would like implemented
in their respective class (ie ISomething be
implemented in CSomething), then some classes
I need to implement many of those interfaces...
Now I am forced to have those classes extend
multiple interfaces, and duplicate the interface
implementation code inside each of them.
I dont mind a little bit of copy/paste, nor
do I care about the compiled classes being
slightly bigger, BUT the problem is that
when I need to change some behaviour in those
interfaces, in the near (or far) future, I will
have their implementation scattered in many
classes... This is dangerously error prone and
not proffesional at all... And I do not think
that including multiple inheritance in the language
could be more error prone than this...
I think the Java team does a 100% perfect brilliant
job, but at this specific point, they "over-tried"
to "protect" the programmers from themselves...
Well, thats all,
I think some next version of Java should support
multiple inheritance. And the Java "warning" could be :
"if you havent missed it till now, then you probably
do not need anyway, so do not bother using it just
because it exists"
Thanks for reading my thoughts,
DimitrisPersonally I never need multiple inheritance of code and I try to avoid inheritance of code whenever possible. A common mistake in OO is too use inheritance as a way of reusing code. Code reuse is much easier, cleaner and more powerful by using composition instead. Only use inheritance for polymorhism (to use multiple implementations for the same interface). An example:
interface A {
void ma();
void maa();
interface B {
void mb();
class C implements A, B {
private A a;
private A c;
private B b;
public void ma() {
a.ma();
public void maa() {
c.maa();
public void mb() {
b.mb();
}This is much more powerful than code reuse through inheritance. In this example I use one method from 'a' and one method from 'c' when I implement interface A. I can change the value of 'a', 'b' and 'c' during runtime, and I dont have to reuse all the code in 'a' and 'b', I can select which code to reuse. This is the power of composition and interfaces. Note that I only access 'a', 'b' and 'c' through the interfaces A and B, never directly through their implementations.
I would recommend you to look at your design and start to think about interfaces and inheritance, not about code reuse though inheritance. -
Hi all,
I am confused by the java statement that "By using interface we can achieve multiple inheritance bcoz java doesn't support Multiple inheritance".
Yes.Ok java doent support Multiple inheritance. Now we know that inheritance means that "one object acquires the property of another object".
So how can it is possible achieve Multiple inheritance by interface.
Interface that contains just undefined methods like below code.
interface Member1
public void eye();
public void nose();
public void mouth();
interface Member2 extends member1
public void neck();
public void hand();
public void stomach();
interface Member3 extends Member1,Member2
public void leg();
class Man implements Member3
public man()
Member3 ref=new Man();
// Here Implements all 7 methods.
Is the above code defines multiple Inheitance?
undefined methods are eye,nose,mouth,neck,handand stomach are fall in Interface Member3 .Yes. But Inheritance means that one object acquires the property of another object.Property means that code and data.
In here, there is no code just declarations of method which is not to be a code .
So How can we say interface achieve multiple inheritance.
Please any one explain and clear my doubt with simple example.
with cheers,
G.GandhiRaj.Multiple inheritance is about aquiring both behavior and attributes from two or more sources. A lot of times, this "is a" relationship is confused with "has a" relationships.
For example, a Book "has a" Page. A Book "is a" Publication. So multiple inheretance in this instance would come from stating that a Book "is a" Publication and "is a" PaperProduct. In this example, you could redesign your model and state that a PaperProduct inherits from Publication. However, a Book doesn't have to be limited to being a PaperProduct, it can also be an ElectronicProduct, thus inhereting attributes and behaviors from this new class as well. In essence, the Book can exist in two forms simulataneously (as many actually do). So you still have the need for multiple inheritance - perhaps.
Interfaces define the behavioral aspects of multiple inheritance. You loose the aquisition of attributes from base classes. In many cases this is acceptable. For the first time I recently found a true need for multiple inheritance in one fo my Java apps. Some would say that my data model is poorly designed then. So I tried restructuring the model and that solve the problem.
It is probably a good idea to completely understand your data model from many dimensions first before resorting to the copying of attributes like I almost did. Don't be locked into a design too quickly. Be willing to change your mind and you will probably find a solution that works. -
Interfaces instead of multiple inheritance?
I've read that "The Java programming language does not permit multiple inheritance , but interfaces provide an alternative."
But I also read contradictory information-There are no method bodies in an interface.
Java interfaces only contain empty methods? Apparently, if I want to share a method among classes, I have to re-write the methods in each class that implements the interface. That doesn't seem at all like multiple inheritance. Am I missing something?
It seems that I will have to cut and paste the implementation code from one class to another, and if I change the methods, I have to cut and paste it all over again.
I've read that interfaces save a lot of time re-writing methods, but how?
Does this really provide the same capabilities as multiple inheritance, or am I missing something?
Thanks,
PatPat-2112 wrote:
I've read that "The Java programming language does not permit multiple inheritance , but interfaces provide an alternative."
But I also read contradictory information-There are no method bodies in an interface. That's not contradictory.
Inheritance is about type, which interfaces provide. It is NOT about sharing code, which is all that's lacking by not having multiple inheritance of implementation.
Java interfaces only contain empty methods? Apparently, if I want to share a method among classes, I have to re-write the methods in each class that implements the interface. That doesn't seem at all like multiple inheritance. Am I missing something? Yup. You're missing the point of inheritance, and the fact that delegation allows you to use an implementation defined in one class in another class.
It seems that I will have to cut and paste the implementation code from one class to another, Nope.
public interface Cowboy {
void ride();
void draw();
public interface Artist {
void sculpt();
void draw();
public interface CowboyArtist extends Cowboy, Artist {
public class CowboyImpl implements Cowboy {
public void ride() {
System.out.println("Giddyup!");
public void draw() {
S.o.p("Bang!");
public class ArtistImpl implements Artist {
public void sculpt() {
S.o.p("Demi Moore in Ghost. Yum!");
public void draw() {
S.o.p("Sketch a picture of a gun.");
public class CowboyArtistImpl implements CowboyArtist { // or implements Cowboy, Artist
private final Cowboy cowboy = new CowboyImpl();
private final Artist artist = new AristImpl();
public void ride() {
cowboy.ride();
public void sculpt() {
artist.sculpt();
public void draw() { // uh-oh, what do we do here?
artist.draw();
cowboy.draw();
}The draw method is not relevant to this particular question. It's an example of one of the problems with MI, and I just included it since it usually comes up int these discussions anyway. Ride and sculpt demonstrate the point about delegation. -
Hi there,
i am working on a multiple adapters scenario and would like to get some help from you experts.
I will try to explain the requirements of it:
1) An external system will send a request to XI (in order to "start" the process) --> SOAP adapter (sender/request)
2) XI will communicate with SAP and retrieve a table from there --> sRFC adapter (receiver)
3) XI will update a table (Oracle DB) of the source system (the external one from step1) --> JDBC adapter (??)
i have been involved in scenarios with SOAP adapter and JDBC separately but not all together.Thus i dont know how to elaborate the third step.In addition i would prefer avoiding the use of BPM if possible.
Questions:
a) What is the best practise here?
b) I am not using WS.response so i dont know how to retrieve back the data to the sorce (that is the target system at the same time) by using the JDBC (cause i need to update a table).
Could you please help me on this?
Thanks in advance and best regards,
DavidHi,
Here is a sample code for RFC lookup
package com.ibis.mapping.lookup.websiteorders;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import com.sap.aii.mapping.api.AbstractTrace;
import com.sap.aii.mapping.api.MappingTrace;
import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.StreamTransformationConstants;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.lookup.Channel;
import com.sap.aii.mapping.lookup.LookupException;
import com.sap.aii.mapping.lookup.LookupService;
import com.sap.aii.mapping.lookup.Payload;
import com.sap.aii.mapping.lookup.RfcAccessor;
import com.sap.aii.mapping.lookup.XmlPayload;
public class RFCLookup implements StreamTransformation
public Map param = null;
public static void main(String[] args)
try
InputStream in = new FileInputStream(new File(
"TestFile.xml"));
OutputStream out = new FileOutputStream(
new File(
"Test.xml"));
System.out.println("Hello");
RFCLookup rfcLookup = new RFCLookup();
rfcLookup.execute(in, out);
catch (Exception e)
System.out.println("ERROR IS :" + e.getMessage());
public void execute(InputStream inputStream, OutputStream outputStream)
throws StreamTransformationException
MappingTrace importanttrace;
importanttrace = (AbstractTrace)param.get(StreamTransformationConstants.MAPPING_TRACE );
RfcAccessor accessor = null;
try
// 1. Determine a channel (Business system, Communication channel)
Channel channel = LookupService.getChannel("BS_name", "Comm_channel_name");
// 2. Get a RFC accessor for a channel.
accessor = LookupService.getRfcAccessor(channel);
importanttrace.addInfo("Accessor Looked up.");
// 4. Create xml payload from the inputStream
XmlPayload payload = LookupService.getXmlPayload(inputStream);
importanttrace.addInfo("Input stream payload fetched");
// 5. Execute lookup.
Payload result = accessor.call(payload);
importanttrace.addInfo("Called the RFC");
// 6. Get the lookup response in new InputStream
InputStream in = result.getContent();
importanttrace.addInfo("got output");
// 7. Transfer the inputstream into outputstream
byte[] buffer = new byte[1024];
for (int read = in.read(buffer); read > 0; read = in.read(buffer))
outputStream.write(buffer, 0, read);
outputStream.write('\n');
outputStream.flush();
catch (LookupException e)
importanttrace.addWarning("Error while lookup " + e.getMessage());
catch (IOException e)
importanttrace.addWarning("Error " + e.getMessage() );
finally
// 8. close the accessor in order to free resources.
if (accessor != null)
try
accessor.close();
catch (LookupException e)
importanttrace.addWarning("Error while closing accessor " + e.getMessage() );
public void setParameter(Map param)
this.param = param;
if (param == null)
this.param = new HashMap();
This code works and all you need is the source RFC interface and target RFC interface.
compile this code and import it as java mapping in interface mapping..
now specify some RFC request in the test tab of interface mapping. the o/p will be response from RFC
Dont forget to modify the name of ur comm channel and business system in the code
Channel channel = LookupService.getChannel("BS_name", "Comm_channel_name");
Edited by: Progirl Progirl on Jul 21, 2008 4:25 PM -
File-XI-multiple IDoc Scenario
Hi there -
I am working on single File-XI-multiple IDoc Scenario and have following questions:
(please keep in mind that there is already an existing multiple IDocs-XI-single File scenario between the same systems)
1. Please provide any detailed step by step documentation from end-to-end.
2. I am thinking it's compulsory to use BPM, is there any way to aviod?
3. Is it possible to update existing IDocs in R/3 directly from the data from XI?
Thanks everyone in advance...
PatHI,
Pls go thru following links-
/people/michal.krawczyk2/blog/2005/12/04/xi-idoc-bundling--the-trick-with-the-occurance-change
Single inbound file -> XI -> Multiple IDOCs in SAP
One file for multiple IDOCs
Hope this helps..
Regards,
Moorthy -
What is single inheritance, multiple inheritance, and describe Java's notio
What is single inheritance, multiple inheritance, and describe Java's notion of an interface?
Can you give me example or reference link? thxSingle inheritance is getting features like data and methods (functions) from a so called parent class. multiple inheritance is the same but you derive features from multiple parent classes (not supported by java). Interfaces are a way around this because you can inherit multiple interfaces. Inheriting from interfaces is like a promise to implement certain methods that these interfaces define but doesn't implement themselves.
check around java.sun.com in the tutorials section, you can probably find a text that describes object oriented program and how it is implemented in java. -
Why java does not support multiple inheritance ???
Hai friends ..iam new to java .. i have doubt ..plz help me
Why java does not support multiple inheritance ???The reasons for omitting multiple inheritance from the Java language mostly stem from the "simple, object oriented, and familiar" goal.
To understand multiple inheritance, the learner needs some level of expertise like virtual derivations etc in c++. Multiple inheritance will allow method duplication, and throws the learner into confusion which method might be called by the compiler in which scenario at run time.
Even though this answer seems to be funny, this is the actual reason why java omitted multiple inheritance of classes.
But java support multiple inheritance of interfaces. Multiple interface inheritance allows an object to inherit many different method signatures with the caveat that the inheriting object must implement those inherited methods. -
How does Java achieve multiple inheritance using interfaces
Java does not allow multiple inheritance through classes as classes might contain methods with same names. what happens if a class implements two interfaces with same method names?
I am really confused abt this? Can anybody help me out?
Message was edited by:
vijkrisyes to avoid the ambiguous functions which can result due to multiple inheritance of classes like in c++ , java doesn't have this through classes. But if you have same method (both return type and parameter) then java doesn't bother and it won't complain as ultimately only one implementation is possible in deriving class even though method declalaration is there in both the interfaces. If return type changes then it won't compile as it can't overide the both methods as they have same name and different return types. thats why inside interfaces they restricted the implementation of methods so that it can work fine in ambiguous scenarios.
-
How java support multiple inheritance by the use of interface.
As per my understanding, Interface is just having the signatures of the methods not the implementation.
So How java support multiple inheritance by the use of interface?
Answer 1: we can institate interface reference by its implemented
class.
����� interface inf...
����� class aa implements inf..
����� class bb implements inf....
Now, inf i = new aa();
inf i = new bb();
Answer 2: We can extends as many interface as we want in the
single
interface.
i.e. interface infFirst....
interface infSecond....
interface infThird....
Now ,
interface ingMulti extends infFrist, infThird...
By above two answers its not prity clear as per the multiple inheritance in C or C++.
i.e.
class first{
method abc();....}
class second{
method bbc()......}
class multi::first::second{
we can call to abc();.....as well as bbc();
-Please give your important suggstion on the same.(Hope I explain it well.)
-JeffThe keyword implement is used only for interfaces not
for abstract class. If i am wrong correct me.I believe your right, but I will double check.
As for the multiple inheritence think about the following code:
class Animal {
// Animal generic stuff in this class
interface Eat {
// Generic stuff that models eating behavior
interface Runs {
// generic methods that model running behavior
public class Horse extends Animal implements Eat, Runs {
// Stuff specific to a horse
}The Animal class is generic but has stuff in it common to all animals.
The Eat interface models behavior that is generic to eating, all living things have to eat something to survive. Herbavore are different from carnivores.
The Runs interface models generic behavior to running, such as speed. A cheeta definately runs faster than a human.
This brings us to the Horse class. It extends the Animal class because it "is-a" animal, and it implements the eat and runs interface because they are behaviors a horse has.
I hope that helps.
Extending an abstract class is the same as extending a regular class with the exception you MUST override all abstract methods in the abstract class. Thats not too difficult but I believe when designing classes, designing an abstract can be more diffecult than modeling the base class, and generic behaviors in interfaces. JMO.
JJ -
Why it is sometimes said that interfaces provide a form of multiple inheritance?
Do you agree that interfaces can provide multiple inheritance? Explain.
Some people say that Java does not support multiple inheritance, and others: a class can implement more than 1 interface. Isn't that multiple inheritance?
Thanks>
Some people say that Java does not support multiple
inheritance, and others: a class can implement more
than 1 interface. Isn't that multiple inheritance?Sort of, but you don't inherit any implementation from an interface.
Maybe you are looking for
-
DW CS4 Help with jump menu opening a new window.
First, I can't believe that Adobe left out an easy to use behavior to do this. I have some jump menus, and I would like the selection to open up a new window and have the content appear there. I saw a couple of old topics here that offered some sugg
-
Multilingual URL is not working in IE11
Multilingual URL is not working in IE11 same URL is working with other browser. Would like to know whether Arabic URL is supported in IE11?
-
How to edit photo text in adobe photoshop?
how to edit photo text in adobe photoshop?
-
Material document cancellation indicator:
Dear Friends, How to find the Material document cancelled or not based on the Material-doc number. Is there any straight forward check or status in the Material document itself. Thanks in advance. RAMAN.
-
I have made an in app purchase then the game has frozen but still taken my money
For the 3rd time now i have made an in app purchase and then the app has frozen but still taken my money. it is getting ridiculous and i want something to be done about this