Assigning a super class attributes to a sub class in an OO way
I think you OO and Pattern forumites might want to help me out on this one.
I started this in the beginners forum, much heat, but not too much light
http://forum.java.sun.com/thread.jsp?forum=54&thread=439107
Make sure you at least read past peoples initial misunderstanding of the problem!
I get handed an object of type Car, and wish to create a new object of type Ferari which is simply an extension of a type Car class object. How can I best do this? Normally I start with the extended type of object and 'fill' that objects attributes, but on this occasion, I receive a simpler object and wish to create a specialised object based on it.
The problem it seems is that assigning just the base object doesn't seem to do it (all fields are null).
// Carpublic class Car { private int engineSize; // More code here}// Feraripublic class Ferrari extends Car { private int turboChargers; /** * Constructor */ public Ferrari(Car car) {// This doesn't seem to work// this = (Ferrari) car; // Hmmm. Tiresome and error-prone assignments setEngineSize(car.getEngineSize()); setColor(car.getColor()); // etc. }}
sure, but the decorator would still BE a JFrame (or
more likely a container)No, in the examples I have seen the Decorator is outside the heirarchy.
Given your many useful posts, I highly doubt that
you're missing a key point in understanding the
decorator pattern.I have to admit that I am not as strong on patterns as I should be. I tend to learn things as I need them. The problem is often you don't realize you need patterns until you learn about them.
MY opinion is that there can be no hard, strict
definition of any pattern; as they are (in Fowler's
words) "half-baked", and require modification to be
implemented in any specific problem.I'll by that.
Is my code a decorator? Yes, in my opinion. I also
think its a delegate (though many would dispute that
saying the delegatee "must" have a reference to the
delegator to be a "true" delegate pattern).I've always called this Composition or a Wrapper. The link I found that agreed with your example actually said that Wrappers and Decorators are synonymous. To me, these seem like very different approaches. That's why I am wondering if my understanding of the Decorator pattern is incomplete or too narrow.
Could you please point me to those references?I think these are two. If you find something that shows your example fits these definitions please let me know.
http://web.media.mit.edu/~tpminka/patterns/Decorator.html
http://www.wikipedia.org/wiki/Decorator_pattern
Similar Messages
-
Can we change the Super class attribute scope in Sub class
Hi.
I created a super class. In that i have 4 attributes. That attributes are PUBLIC.
I created a sub class. In that i got all super class attributes. I want to change that attributes as a Private. Is it possible.
If it is possible.Give me an Example with code or Pseudo code.
Regards.
Krishna.Hi Krishna,
It is not possible... If you declare the Attributes again in Subclass of the same name as that of Super class
then the way of accessing them would be different from that of attributes in the main class.
Hope this would help you
Good luck
Narin -
Assigning a super class attributes to a sub class
I get handed an object of type Car, and wish to create a new object of type Ferari which is simply an extension of a type Car class object. How can I best do this? Normally I start with the extended type of object and 'fill' that objects attributes, but on this occasion, I receive a simpler object and wish to create a specialised object based on it.
The problem it seems is that assigning just the base object doesn't seem to do it (all fields are null).
// Car
public class Car {
private int engineSize;
// More code here
// Ferari
public class Ferrari extends Car {
private int turboChargers;
* Constructor
public Ferrari(Car car) {
// This doesn't seem to work
// this = (Ferrari) car;
// Hmmm. Tiresome and error-prone assignments
setEngineSize(car.getEngineSize());
setColor(car.getColor());
// etc.
} Thanks for any suggestions!Wait - sorry, it's more like a copy constructor. I missed that the first time through.
There's no good way around it - you'll have to get those values in there somehow. Unless there's a reasonable default value for all the Ferrari members that aren't part of Car, you'll have a problem with this because of the slicing problem.
It's as if you're writing a C++ copy constructor. It's just an alternative to the Java clone method.
If there are really that many attributes, maybe you can assign them using the Java reflection API.
Unless there are hundreds of them, type them once and be done with it. If there ARE hundreds of them, you might want to consider refactoring your class. It's too big!
You'll have to do that kind of thing when you write the equals and hashCode methods for your classes. Just do it! - MOD -
Is it possible to OVERLOAD a super-class method in a sub-class?
Hi all,
I have a query that
Is it possible to OVERLOAD a super-class method in a sub-class?
If it is possible, please give me an example.
Thanks,
HariHi,
Is the method int Display(int a){} overloading
the super-class's void Display() method? If
possible, please clarify this and how it would be
method overloading?
hanks,
Hari
Hi Hari,
Yes, it is possible. Look at this piece of code:
class Senior
void Display()
System.out.println("Super class method");
class Junior extends Senior
int Display(int a)
System.out.println("Subclass method: "+a);
return(a+10);
}> }
class example
public static void main(String args[])
Junior j = new Junior();
j.Display();
System.out.println("Subclass method
od "+j.Display(5));
Is this what you were asking? Hope this helped.Hi,
I guess you guys are confused here...
Overloading is achieved by methods in the same class...
Overriding is across a superclass subclass methds. -
Can we chagne Super class method parameters in Sub class
Hi,
I created a super class. In that class i created a method. That method is having 4 input parameters and 4 export parameters.
I created a sub class for that super class. I need to use only 2 input parameters in this class rather than 4 parameters. I want to delete 2 Input parameters in the sub class of the super class method. Is it possible.
If possible. can we give an simple code or pseudo code?
regards,
krishnaHi,
I think you can not.
Because, only public attributes can be inherited and they will remain public in the subclass.
for further detail check,
http://help.sap.com/saphelp_nw70/helpdata/en/1d/df5f57127111d3b9390000e8353423/content.htm
regards,
Anirban -
How to inherit super class constructor in the sub class
I have a class A and class B
Class B extends Class A {
// if i use super i can access the super classs variables and methods
// But how to inherit super class constructor
}You cannot inherit constructors. You need to define all the ones you need in the subclass. You can then call the corresponding superclass constructor. e.g
public B() {
super();
public B(String name) {
super(name);
} -
Accessing data in a class when not in the class library
Spoiler (Highlight to read)
Hi,
I'm fairly new to labview classes and am wondering if it is possible to make public or read the value coming from a lvclass control.
If I highlight the control all the values are listed as private and I can't unbundle the class, of course once I make a vi a member of the lvclass I can unbundle the class. However there are two elements that I want o be globally available, is this possible?
SeanYou need to select your class, not the ctl.
This is the same thing as making a member vi for the class, it's just a shortcut for making a .vi that can output the private date.
( The way LabVIEW has implemented the OOP, all class attributes are private. And there are no way to make them public or protected. The only way to access the data from outside is by making a Accessor. )
Here are some reading: http://zone.ni.com/devzone/cda/tut/p/id/3574 -
Trouble assigning sub class to super class array
Hi,
I would greatly appreciate some help with the following:
I want to assign a sub class to a super class array but the following code does not work
where the board is comprised of the super class
private static void makeMove( int X, int Y, int moveX, int moveY )
ChessPiece tempChessPiece = ( ChessPiece ) board[ X ] [ Y ];
board[ X ] [ Y ].setType( UNDEFINED );
board[ moveX ] [ moveY ] = tempChessPiece;
}I have got this code to work but it does not appear
to be very efficient to me as i dont recycle the
objects.
Any thoughts?The objects will be recycled by the garbage collector. It's very efficient so there's very little performance penalty in creating objects and releasing objects.
Still, another alternative is to represent an empty square with null. In that case the code becomes,
private static void makeMove( int selectedX, int selectedY, int moveToX, int moveToY ) {
board[moveToY][moveToX] = board[selectedX][selectedY]; // piece to new position
board[selectedX][selectedY] = null; // remove from old
}I don't know your exact design but that should work. It's kind of natural too. If a square is empty there's no piece object there at all. No new object has to be created and that explicit cast is gone. -
Instantiation of similar object over a super class deciding the sub class
Hello all
First, sorry if I'm duplicating an already answered question. I didn't searched very deep.
Initial position:
I have 2 Object (A1 and A2) which share the most (about 90%) of their instance variables an the associated methods. The values of the instance variables are retrieved in the real implementation from a stream. Depending of the data of the stream, I have to instantiate either a A1 or A2 object.
A test implementation (using an int in case of the stream):
The super class A:
package aaa;
public class A
protected int version = -1;
protected String name = null;
protected AE ae = null;
protected A()
protected A(int v)
// Pseudo code
if (v > 7)
return;
if (v % 2 == 1)
this.version = 1;
else
this.version = 2;
public final int getVersion()
return this.version;
public final String getName()
return this.name;
public final AE getAE()
return this.ae;
}The first sub class A1:
package aaa;
public final class A1 extends A
protected A1(int v)
this.version = v;
this.name = "A" + v;
this.ae = new AE(v);
}The second subclass A2:
package aaa;
import java.util.Date;
public final class A2 extends A
private long time = -1;
protected A2(int v)
this.version = v;
this.name = "A" + v;
this.time = new Date().getTime();
this.ae = new AE(v);
public final long getTime()
return this.time;
}Another class AE:
package aaa;
public class AE
protected int type = -1;
protected AE(int v)
// Pseudo code
if (v % 2 == 1)
this.type = 0;
else
this.type = 3;
public final int getType()
return this.type;
}To get a specific object, I use this class:
package aaa;
public final class AFactory
public AFactory()
public final Object createA(int p)
A a = new A(p);
int v = a.getVersion();
switch (v)
case 1:
return new A1(v);
case 2:
return new A2(v);
default:
return null;
}And at least, a class using this objects:
import aaa.*;
public final class R
public static void main(String[] args)
AFactory f = new AFactory();
Object o = null;
for (int i = 0; i < 10; i++)
System.out.println("===== Current Number is " + i + " =====");
o = f.createA(i);
if (o instanceof aaa.A)
A a = (A) o;
System.out.println("Class : " + a.getClass().getName());
System.out.println("Version : " + a.getVersion());
System.out.println("Name : " + a.getName());
System.out.println("AE-Type : " + a.getAE().getType());
if (o instanceof aaa.A2)
A2 a = (A2) o;
System.out.println("Time : " + a.getTime());
System.out.println();
Questions:
What would be a better way to encapsulate the logic into their respective objects ? Is there a way to let the super class A itself identify the type of the object and then extend from A to either A1 or A2 ?
Thanks in advance
AndreasHello jduprez
First, I would thank you very much for taking the time reviewing my problem.
Just for the record: have you considered regular serialization? If you control the software at both ends of the stream, you could rely on standard serialization mechanism to marshall the objects and unmarshall them automatically.In my case, I can't control the other site of the stream. At the end, the data comes from a FileInputStream and there aren't objects on the other site, only pur binary data.
- It seems you have one such factory class. Then you already have encapsulated the "determine class" logic, you don't need to add such logic in superclass A.I thought from an OO view, that the super class A is responsible of doing that, but that's where the problem starts. So at the end, it's better doing it in the factory class.
- A itself encapsulates the logic to load its own values from the stream.
- A1 and A2 can encapsulate the logic to load their own specific value from a stream (after the superclass' code has loaded the superclass' attributes values).
My advise would be along the lines of:
public class A {
.... // member variables
public void load(InputStream is) {
... // assign values to A's member variables
// from what is read from the stream.
public class A1 extends A {
... // A1-specific member variables
public void load(InputStream is) {
super.load(is);
// now read A1-specific values
public class AFactory {
public A createA(InputStream is) {
A instance;
switch (is.readFirstByte()) {
case A1_ID:
a = new A1();
break;
case A2_ID:
a = new A2();
break;
a.load(is);
}The example above assumes you have control over the layout of the data in the stream (here for a given A instance, the attributes defined in A are read first, then come the subclass-specific attributes.
The outcome is: you don't have to create a new A( ) to later create another instance, of a subclass.I like the idea. In the AFactory, is the "A instance;" read as "A a;" ?
Is there a way to let the super class A itself identify the type of the object and then extend from A to either A1 or A2 ?Note I initially read this question as "can an instance of a class mutate into another class", to which the answer is no (an object has one single, immutable class; it is an instance of this class, and of any superclass and superinterface, but won't change its class at runtime).Yes, I have been thinking about a way for mutating into a subclass to keep the already initialized values from the A class without copying or parsing again. But preventing an instance of an A class will be my way. So, in this aspect, Java didn't changed in the last 10 years... It's a long time ago I've used Java for some real projects.
You can, however, create an instance of another class, that copies the values off a priori A instance. Your example code was one way, another way could be to have a "copy constructor":
public class A {
public A(A model) {
this.att1 = model.att1;
this.att2 = model.att2;
public class A1 {
public A1(A model) {
super(model);
... // do whatever A1-specific business
)Still, I prefer my former solution less disturbing: I find the temporary A instance redundant and awkward.Nice to know. I prefer the first solution too.
Thank you again for the help and advices. My mind is searching sometimes for strange solutions, where the real is so close ;-)
Andreas -
Exception in super and sub class
when super class method throws an exception then sub class overridden method can throws child exception but when we talk about constructor why we throws parent class exception in derived class constructor????
tcbhardwaj wrote:
C() throws Throwable // why here parent of Exception class
void ok() throws ArithmeticException // why here child of RunTimeException classFirst, you never need to declare a throws clause for unchecked exceptions--RuntimeException, Error, and their descendants.
However, there are a couple of general rules for checked exceptions (such as IOException, SQLException, etc.). As you're studying these, keep in mind that a throws clause is a contract that promises what the method will not do. In particular, it doesn't promise that the method will throw those exceptions. It promises that it will not throw any other checked exceptions not covered by that throws clause.
1. A child method that overrides a parent method cannot throw any checked exception outside what's covered by the parent's throws clause. So if the parent method declared throws IOException, the child cannot declare throws Exception, or throws SQLException, because both of those are outside the IOException "sub-hierarchy."
2. A child method that overrides a parent method can declare to throw less than the parent throws. This is because, if the parent promises not to throw outside of some set, and the child promises not throw outside of a subset of that set, then clearly he's also not throwing outside of the parent's set. If the parent method declares throws SQLException, IOException, then the child can declare no exceptions at all, or just SQLException, or just IOException, or any combination of any of the subclasses of SQLE and IOE.
Rules 1 and 2 do not apply in the case of constructors, because no constructor can ever override another constructor.
3. When any method or constructor, A, invokes any other method or constructor, B, then any checked exception declared to be thrown by B must be either caught or declared to be thrown by A. If A catches or throws a parent of an exception thrown by B, then he's also implicitly catching or throwing the one that B mentions. -
Servicegen for sub-class inside vector variable of Super
java.lang.NoSuchMethodError
at com.netsboss.WSBE.model.QueryItemCodec.typedInvokeGetter(QueryItemCod
ec.java:87)
at com.netsboss.WSBE.model.QueryItemCodec.invokeGetter(QueryItemCodec.ja
va:56)
at weblogic.xml.schema.binding.BeanCodecBase.gatherContents(BeanCodecBas
e.java:295)
at weblogic.xml.schema.binding.CodecBase.serializeFill(CodecBase.java:25
3)
at weblogic.xml.schema.binding.CodecBase.serialize(CodecBase.java:195)
at weblogic.xml.schema.binding.RuntimeUtils.invoke_serializer(RuntimeUti
ls.java:184)loop
at weblogic.xml.schema.binding.RuntimeUtils.invoke_serializer(RuntimeUti
ls.java:170)
QueryItem {
private Vector airItiners;
public Vector getAirItiners() {
return airItiners;
public class AirItinerary implements Serializable{}
QueryItem is my return class. The return result will include sub class AirItinerary
in QueryItem's Vector. I notice servicegen will only generate stub and web.xml
for QueryItem.
I get above error, when the result return to client. How to generate necessary
sub-class inside a vector variable of Super class?
StephenHi Stephen,
write my own ser/deser? Any other quick way?Our excellent support group ([email protected]) may be able to help with
an alternative solution. If you could create a small reproducer, then
this will help them with a clear picture of your goal.
One more problem, wls deloy my WSBE.ear as a war correctly. But error show noDouble check the console log for any messages. Also try:
http://[host]:[port]/[contextURI]/[serviceURI]
See: http://edocs.bea.com/wls/docs70/webserv/client.html#1051033 and
also check the console to verify the app is or is not deployed. See:
http://edocs.bea.com/wls/docs70/programming/deploying.html
HTHs,
Bruce
Stephen Zeng wrote:
>
Hi Bruce:
Our company use wsl7.0. We are not able to update to wls8 in this project. Do
I have to
write my own ser/deser? Any other quick way?
sub class variable:
public class AirItinerary implements Serializable{
private String air;
private Vector flightItem; //sub class of AirItineray
One more problem, wls deloy my WSBE.ear as a war correctly. But error show no
deloyment found. web-services.xml has been generated by servicegen under web-inf
path. Thanks Bruce.
Stephen
Bruce Stephens <[email protected]> wrote:
Hi Stephen,
The java.util.vector should be converted to a SOAP Array, see:
http://edocs.bea.com/wls/docs81/webserv/assemble.html#1060696 however
the issue of the sub-class is most likely the problem. Can you simplify
the data types? You may just have to write your own ser/deser, see:
http://edocs.bea.com/wls/docs81/webserv/customdata.html#1060764
This is with WLS 8.1, right?
Thanks,
Bruce
Stephen Zeng wrote:
java.lang.NoSuchMethodError
at com.netsboss.WSBE.model.QueryItemCodec.typedInvokeGetter(QueryItemCod
ec.java:87)
at com.netsboss.WSBE.model.QueryItemCodec.invokeGetter(QueryItemCodec.ja
va:56)
at weblogic.xml.schema.binding.BeanCodecBase.gatherContents(BeanCodecBas
e.java:295)
at weblogic.xml.schema.binding.CodecBase.serializeFill(CodecBase.java:25
3)
at weblogic.xml.schema.binding.CodecBase.serialize(CodecBase.java:195)
at weblogic.xml.schema.binding.RuntimeUtils.invoke_serializer(RuntimeUti
ls.java:184)loop
at weblogic.xml.schema.binding.RuntimeUtils.invoke_serializer(RuntimeUti
ls.java:170)
QueryItem {
private Vector airItiners;
public Vector getAirItiners() {
return airItiners;
public class AirItinerary implements Serializable{}
QueryItem is my return class. The return result will include sub classAirItinerary
in QueryItem's Vector. I notice servicegen will only generate stuband web.xml
for QueryItem.
I get above error, when the result return to client. How to generatenecessary
sub-class inside a vector variable of Super class?
Stephen -
Less dumb follow-up question about super/sub classes in WDJ?
This is a follow-up question to the question which Maksim answered in this thread:
Dumb question about super/sub classes in WDJ
Question:
Is there any kind of weird C++-like statement that you can put at the top of a WDJ module to force the module to interpret any reference to superclass A as a reference to some specific subclass B of A ???David,
1. Java has no preprocessor, so C++ tricks are not available. Also I would not recommend such tricks even in C++ if you don't want to turn your colleagues working with same code into personal enemies.
2. The phrase "easier to create a WDJ custom class loader " makes me smile. First, it's not that simple to interfere WDJ class loading scheme. Plus custom class loaders is not trivial Java topic per se.
3. The problem "replace all A-s with B-s" is typically solved using one or another GoF creation patterns, like <a href="http://en.wikipedia.org/wiki/Abstract_factory_pattern">Abstract Factory</a> or <a href="http://en.wikipedia.org/wiki/Factory_method_pattern">Factory Method</a>. You may use them with custom class loader, if you really want to
By the way, all UI controls in WD are created using Abstract Factory (role played by view). So you may use this as good example.
Valery Silaev
SaM Solutions
http://www.sam-solutions.net -
Sub class calls super in constructor
when a sub calss calls super() in its constructor is it overriding the constructor of base class ?
Class A {
A(Strin neme){
class B extend A{
B(){
super("test")
Systemout......
I donot know the term explaning this feature is it called overriding constructor?miro_connect wrote:
so how to describe this code, are there any terms to explain this methodology to not technical guys ?Yeh. "Magic". Seriously. There's little point explaining such things to non-technical people. Ever tried to teach your mum how to program a VCR?
By definition, non-tech people will simply not understand what you're on about, and won't need to. -
Sub class will allocate seperate memory for super class instance variable?
class A
int i, j;
void showij()
System.out.println("i and j: " + i + " " + j);
class B extends A
int k;
void showij()
System.out.println("i and j: " + i + " " + j);
what is size of class B will it be just 4 byte for k or 12 bytes for i, j and k ?
will be a seperate copy of i and j in B or address is same ?
thank uamit.khosla wrote:
just to add on...if you create seprate objects of A and B, so the addresses will be different. We cant inherit objects, we inherit classes. It means if you have an object of A and another object of B, they are totally different objects in terms of state they are into. They can share same value, but its not compulsary that they will share same values of i &j.
Extending A means to making a new class which already have properties & behaviour of A.
Hope this help.That is very unclear.
If you create two objects, there will be two "addresses", and two sets of member variables.
If you create one object, there will be one "address", and one complete set of non-static member variables that is the union of all non-static member variables declared in the class and all its ancestor classes. -
Access to class attributs by coding in its mother class method definition
Hi all,
How can I retrieve information about a class attributs by coding?
And is it possible to access to the attributs of the Child class from the Mother class?
REPORT ztest_method.
****** CLASS mother DEFINITION
CLASS mother DEFINITION.
PUBLIC SECTION.
METHODS: get_data.
ENDCLASS. "mother DEFINITION
****** CLASS child DEFINITION
CLASS child DEFINITION inheriting from mother.
ENDCLASS. "child DEFINITION
******* CLASS mother IMPLEMENTATION
CLASS mother IMPLEMENTATION.
METHOD get_data.
***Can I access to child class attributs here?
ENDMETHOD. "get_data
ENDCLASS. "mother IMPLEMENTATION
DATA oref TYPE REF TO CHILD.
DATA: method TYPE string.
DATA: cla_name(20).
START-OF-SELECTION.
CREATE OBJECT oref .
CALL METHOD oref->method). "Here I want to access to this class's attribut without redefine itHi,
a very easy way is to define an attribute TYPE REF TO DATA in the super class and write generic access methods which work with it by dereferencing it and assigning a field symbol. This might even save you the effort of creating a class hierarchy, because one class may be able to handle all the data objects whose types are only known at run-time.
In the below example, the only specific thing about the sub class is the constructor in which the data object is created and typed:
REPORT ztesta.
* CLASS lcl_mother DEFINITION
CLASS lcl_mother DEFINITION.
PUBLIC SECTION.
METHODS get_data EXPORTING es_data TYPE any.
METHODS set_data IMPORTING is_data TYPE any.
PROTECTED SECTION.
DATA mr_data TYPE REF TO data.
ENDCLASS. "lcl_mother DEFINITION
* CLASS lcl_child1 DEFINITION
CLASS lcl_child1 DEFINITION INHERITING FROM lcl_mother.
PUBLIC SECTION.
METHODS constructor.
ENDCLASS. "lcl_child1 DEFINITION
DATA:
lr_child TYPE REF TO lcl_mother,
ls_but000_in TYPE but000,
ls_but000_out type but000.
START-OF-SELECTION.
CREATE OBJECT lr_child TYPE lcl_child1.
ls_but000_in-partner = '0000004711'.
lr_child->set_data( ls_but000_in ).
lr_child->get_data( IMPORTING es_data = ls_but000_out ).
write: / ls_but000_out-partner.
* CLASS lcl_mother IMPLEMENTATION
CLASS lcl_mother IMPLEMENTATION.
METHOD get_data.
FIELD-SYMBOLS:
<fs_data> TYPE ANY.
ASSIGN mr_data->* TO <fs_data>.
MOVE-CORRESPONDING <fs_data> TO es_data.
ENDMETHOD. "get_data
METHOD set_data.
FIELD-SYMBOLS:
<fs_data> TYPE ANY.
ASSIGN mr_data->* TO <fs_data>.
MOVE-CORRESPONDING is_data TO <fs_data>.
ENDMETHOD. "set_data
ENDCLASS. "lcl_mother IMPLEMENTATION
* CLASS lcl_child1 IMPLEMENTATION
CLASS lcl_child1 IMPLEMENTATION.
METHOD constructor.
super->constructor( ).
CREATE DATA mr_data TYPE but000.
ENDMETHOD. "constructor
ENDCLASS. "lcl_child1 IMPLEMENTATION
Another variant would be to define an attribute MV_DATA which is typed individually in each sub class and program dynamically against it in the super class using field symbols.
*& Report ZTESTA
REPORT ztesta.
* CLASS lcl_mother DEFINITION
CLASS lcl_mother DEFINITION.
PUBLIC SECTION.
METHODS get_data EXPORTING es_data TYPE any.
METHODS set_data IMPORTING is_data TYPE any.
ENDCLASS. "lcl_mother DEFINITION
* CLASS lcl_child1 DEFINITION
CLASS lcl_child1 DEFINITION INHERITING FROM lcl_mother.
PUBLIC SECTION.
DATA: ms_data TYPE but000.
METHODS constructor.
ENDCLASS. "lcl_child1 DEFINITION
* CLASS lcl_child2 DEFINITION
CLASS lcl_child2 DEFINITION INHERITING FROM lcl_mother.
PUBLIC SECTION.
DATA: ms_data TYPE t000.
METHODS constructor.
ENDCLASS. "lcl_child1 DEFINITION
DATA:
lr_child1 TYPE REF TO lcl_mother,
lr_child2 TYPE REF TO lcl_mother,
ls_but000 TYPE but000,
ls_t000 TYPE t000.
START-OF-SELECTION.
CREATE OBJECT lr_child1 TYPE lcl_child1.
lr_child1->get_data( IMPORTING es_data = ls_but000 ).
WRITE: / ls_but000-partner.
CREATE OBJECT lr_child2 TYPE lcl_child2.
lr_child2->get_data( IMPORTING es_data = ls_t000 ).
WRITE: / ls_t000-mwaer.
* CLASS lcl_mother IMPLEMENTATION
CLASS lcl_mother IMPLEMENTATION.
METHOD get_data.
FIELD-SYMBOLS:
<fs_data> TYPE ANY.
ASSIGN ('MS_DATA') TO <fs_data>.
es_data = <fs_data>.
ENDMETHOD. "get_data
METHOD set_data.
FIELD-SYMBOLS:
<fs_data> TYPE ANY.
ASSIGN ('MS_DATA') TO <fs_data>.
<fs_data> = is_data.
ENDMETHOD. "set_data
ENDCLASS. "lcl_mother IMPLEMENTATION
* CLASS lcl_child1 IMPLEMENTATION
CLASS lcl_child1 IMPLEMENTATION.
METHOD constructor.
super->constructor( ).
SELECT SINGLE * FROM but000 INTO ms_data.
ENDMETHOD. "constructor
ENDCLASS. "lcl_child1 IMPLEMENTATION
* CLASS lcl_child2 IMPLEMENTATION
CLASS lcl_child2 IMPLEMENTATION.
METHOD constructor.
super->constructor( ).
SELECT SINGLE * FROM t000 INTO ms_data.
ENDMETHOD. "constructor
ENDCLASS. "lcl_child2 IMPLEMENTATION
I hope this helps!
Regards,
Thorsten
Maybe you are looking for
-
Audio Line-In Port Not Working
I plugged a Shure mic into the Audio-In Port and is doesn't work. I'm using FCP Voice-Over but I get no audio on Soundtrack either. Worked with all the settings and preferences for audio. Also tested a second mic which also doesn't work. I read some
-
How to get the date of 60 days before 1999/03/01?
Hi, I have a question about Date and GregorianCalendar here. I have a string "1999/03/01" and I would like to know the date that 60 days before 1999/03/01. What should I do it? I only went this far: DateFormat dateFormat = new SimpleDateFormat("yyyy/
-
When I attempt to add an item to my cart on the desktop version (tried Chrome or IE), I get an error "There was a problem adding your product to cart" in a red bar with a white triangle. I've cleared my cache, logged out and back in and this unfortu
-
No. of javabeans in jsp pages
Hi, If i am having 180-200 textfield in a jsp page and i want to submit the whole data in database table then how many beans should be used to improve the performance . Can it be done using only single bean and if not then what should be the criteria
-
How can we create the pushbuttons on the Maintenanace view screen ont the table maintenance generator ?