Flex/AS3 Best way to construct a derived class instance from an existing base class instance?

What is the best way to handle the instantiation of a derived class from an existing base class.
I have a base class which is being created via remote_object [RemoteClass alias] from the server.   I have other specialized classes that are derived from this baseclass, but serialization with the server always happens with the base class.     The base class has meta data that defines what the derived class is, for example
[RemoteClass (alias="com.myco...')]
public Class Base
     public var derivedType:String;
     public function Base()
public Class Derived extends Base
     public "some other data"
     public function Derived()
In my Cairgorm command which retrieves this object from ther server I want to do this:
public function result (event: Object):void
    var baseInstance:Base = event.result;
     if (baseInstance.derivedType = "derived")
          var derivedInstance:Derived = new Derived( baseInstance );
What is the most efficient way of doing this?   It appears to me that doing a deep-copy/clone and instantiation of the derived class is pretty inefficient as far as memory allocation and data movement via the copy.

Thanks for the assistance.  Let me try to clarify.
MY UI requires a number of composite classes.    The individual components of the composite classes are being transfered to/from the server at different times depending upone which component has changed state.    The construction of the composite classes from the base class happens in my clients business logic.
Composition happens in a derived class; but server syncronization happens using the base class.    When I recieve the object from Blazeds through the remote object event, it is in the form of the base class.  I then need to instantiate the derived class and copy the elements of the base class into it (for later composite construction).   And likewise when sending the base class back to the server, I need to upcast the derived class to its base class.   But in this case just a mere upcast does not work.  I actually need to create a new base class and copy the attrbutes into it.  I believe this is limitation of how remoting works on Flex/AS3.
My question is, what is the best way to turn my base class into it's derived class so further composite construction can take place.   The way I am currently doing it is to create a  load method on the base class, that takes the base class as on argument.  The load function, copies all of the instance attribute references from the base class to the target class.
public Class Base
     public function Base()
     public function load(fromClass:Base)
    {  //  copy the references for all of the instance attributes from the fromClass to this class }
Then,  after I recieve the base class from the server.   I create a new derived class and pass the base class into the load function like this:
            for (var i:int=0; i < event.result.length; i++) {
                var derived:Derived = new Derived();
                derived.load(event.result[i]);
The drawbacks of this approach is that it now requires 2 extra instance creations per object serialization.   One on recieving the object from the server and one sending it to the server.    I assume copying references are pretty efficient.  But, there is probably some GC issues.     The worst of it is in code maintenance.   The load function now has to be manually maintained and kept in sync with the server class.
It would be interesting to hear how others have solved this problem.      The server side is an existing application with around 2M LOC, so changing the code on the server is a non-starter.
Thanks for your help.

Similar Messages

  • What is the best way to transfer my music and pictures from my old PC to my new Macbook Pro?

    What is the best way to transfer my music and pictures from my old PC to my new Macbook Pro?

    This may help;
    http://www.apple.com/support/macbasics/migration/
    Ciao.

  • What is the best way to copy a DVD i made from iMovie?  It was HD720 and I don't want to lose any quality in the copies.

    What is the best way to copy a DVD I made from iMovie?  It was HD720 and I don't want to lose any quality in the copies.  I need to distribute it to about 20 people. It's 42 minutes long.

    You will need to save it as a video to the camera roll.
    Import it into windows as you would a photo.
    Then purchase DVD authoring software, and create a DVD.

  • What is the best way to transfer apps, contacts, et cetera from one iPhone (3G) and computer (2006 MacBook) to a new iPhone (4S) and computer (early 2011 MacBook Pro)?  I have already moved music, among other things using Migration Assistant.

    What is the best way to transfer apps, contacts, et cetera from one iPhone (3G) and computer (2006 MacBook) to a new iPhone (4S) and computer (early 2011 MacBook Pro)?  I have already moved music, among other things using Migration Assistant but I cannot locate contacts or Apps.

    transfer just SOME of the applications
    it's all or none, i'm afraid.

  • What's the best way to transfer (not forward) a call from one iPhone to another?

    What's the best way to transfer (not forward) a call from one iPhone to another? Is there an app available that does this? I'm asking about receiving a call, then transferring that caller to another iPhone on a separate number and then disconnecting while those two users are joined up in a conversation.

    Ask your carrier. This would be a feature provided by them.

  • I have a PPC iMac 10.4.11 and will shortly buy a new i Mac.  What is the best way to transfer all my HD date from old to new? Thank you!

    I have a PPC iMac 10.4.11 and will shortly buy a new i Mac.  What is the best way to transfer all my HD date from old to new? Thank you!

    Migrating from PPC Macs to Intel Macs:
    https://discussions.apple.com/docs/DOC-2295
    How to use Migration Assistant:
    http://support.apple.com/kb/HT4413?viewlocale=en_US
    http://support.apple.com/kb/TS1963
    Troubleshooting Firewire target disk mode:
    http://support.apple.com/kb/HT1661

  • What is the best way to backup my computer before upgrading from OSX 10.5.8 to 10.6?

    What is the best way to backup my computer before upgrading from OSX 10.5.8 to 10.6? I just purchased a WD portable external hard drive.

    Use Carbon Copy Cloner http://www.bombich.com/index.html or SuperDuper.  http://www.shirt-pocket.com/SuperDuper/SuperDuperDescription.html  Both make a bootable copy of everything on your hard drive.

  • What is the best way to move my itunes music library from my old computer to my new one?

    what is the best way to move my itunes music library from my old computer to my new one?

    Home Sharing is option A.
    http://support.apple.com/kb/HT3819
    Option B is consolidating the library to an external HD.
    http://support.apple.com/kb/ht1364
    http://support.apple.com/kb/ht1751
    Or you can use one of the other 8000 methods. I just prefer these two.

  • Why cannnot derived class pointer point to a base class object?

    Hi,
    Pleaseeee... explain me why cannot the derived class pointer point to a base class object.
    I know that Base class pointer can point to a derived class object.
    Thanks & Regards,
    Vig....

    Example:
    class Base
    { public: void foo(); } * pBase;
    class Derived : public Base
    { public: void bar(); } * pDerived;
    Now, what would happen if you assign pDerived = new Base() and then call pDerived->bar()?By forbidding such an assignment, compiler prevents you from writing error-prone code.

  • AS3 Best way to clear an array

    What is the best way to clear an array? (performance and resources)
    array.length = 0;
    array = [];
    array.splice(0);

    that's creating a new array which is extra work, and it's adding an array to the objects that flash will gc, and that's extra work.
    assigning the length to 0 is the most efficient way to clear an array.

  • What Is the best way to upload and download psd files from Photoshop to Photoshop Touch? [was:Re]

    What Is the best way to up load and down load psd files from desktop photo shop to photo shop touch? For on the go touch up or. I'm using psd files at 90 percent 300 depi when in photo shop on desktop. To ps touch

    Hi Bford225,
    I'd recommend using your favorite web browser and going to https://creative.adobe.com/files for uploading from the computer.
    Keep in mind tablet capabilities are much less than a computer, so large files might take a long time to download and be very system intensive to work on. Although you can import files up to 12 megapixels I'd recommend something more mid range, like 6 or 7 megapixels, ie 2880 x 2160 or 3072 x 2304.
    Also, PSD files are flattened when imported into Photoshop Touch.
    Hope that helps,
    -Dave 

  • What is the best way to send large, HD video files from the iPad?

    Hello,
    My department is looking to purchase between 50 and 150 new iPads. We hold conferences where participants take short, 3-minute videos of themselves in situations they have been trained for. The idea was that after they have taken the video, they could simply email these videos to themselves, negating the need to hook the device up to a computer, transfer the video over to a flash drive, and ensure that drive gets back to the right person.
    Now that I have the first one, I'm finding any video longer than 45s or so can't be sent via email because it's too large.
    Are you kidding?
    The file I was just able to send was 7.5MB. That's the biggest video I can send from this thing? Why even give us the ability to take HD video if we can't *do* anything with it?
    But, I digress.
    What I'm looking for is the best way to get video off the iPads and into the hands of our participants. Are there apps on the App Store which might convert whatever video we take to an emailable size? I thought about setting everyone up with Apple IDs and having them use iMessage since there is no limit on file size, but of course you must own an Apple device in order to do that, and it still doesn't solve getting it on their computers.
    Any help here would be greatly appreciated.
    Thanks!
    --Rob

    You could try uploading them to a joint dropbox account that they could then download them from....but how fast it is will depend on the internet connection available.

  • What is the best way to move all of my data from an iPad 4 to an air?

    Santa brought an iPad Air and I need to transfer my data and apps from the old iPad I have had.  Help on the best way to do this since I played with the new machine yesterday and some of the things transfered but not all.
    Thanks!

    How to Transfer Everything from an Old iPad to New iPad
    http://osxdaily.com/2012/03/16/transfer-old-ipad-to-new-ipad/
    iOS: Transferring information from your current iPhone, iPad, or iPod touch to a new device
    http://support.apple.com/kb/HT2109
    Moving Content to a New iPad
    http://tinyurl.com/qzk2a26
    Transferring your prepaid cellular data account depends on your carrier. AT&T lets you move it yourself when you go to Cellular Data in Settings and log into your account with your previous AT&T user name and password. For iPads with Sprint service, you can set up an account on the new iPad and contact Sprint Customer Care (888-211-4727 and go through the menus) to deactivate the old plan and get credit for unused service. For Verizon, call the company’s customer service number for mobile broadband support (800-786-8419) and ask to have your account transferred.
     Cheers, Tom

  • Best way to return an array of values from c++?

    I have a a group of structs made of a mix of primitive types in c++. I need to return these to Java but Im not sure the best way to return them quickly.
    Should I create a class corresponding to the structure in Java then create the class in C++ and set its fields and return that? Or should I create arrays of different primitive types and return those? Can I even do that? Say, store a group of arrays of different types in a jobjectArray and return that? If I can, what would be the return type? Object[][]?

    Java side:
    package jni;
    import java.nio.ByteBuffer;
    import java.nio.ByteOrder;
    * @author Ian Schneider
    public class Struct {
        static {
            System.loadLibrary("struct");
        public static void doit() {
            ByteBuffer bytes = ByteBuffer.allocateDirect(structSize());
            bytes.order(ByteOrder.nativeOrder());
            getData(bytes);
            System.out.println("int : " + bytes.getInt());
            System.out.println("double : " + bytes.getDouble());
        private static native void getData(ByteBuffer bytes);
        private static native int structSize();
        public static void main(String[] args) throws Exception {
            doit();
    }C side (I'm not a C programmer, so be nice):
    #include "jni_Struct.h"
    struct foo {
      int x;
      double y;
    } foo;
    JNIEXPORT void JNICALL Java_jni_Struct_getData
      (JNIEnv * env, jobject obj, jobject buf) {
      struct foo * f = (void*) malloc(sizeof(foo));
      f->x = 123;
      f->y = 456.;
      void * data = (void *) (*env)->GetDirectBufferAddress(env,buf);
      memcpy(data,f,sizeof(foo));
      free(f);
    JNIEXPORT jint JNICALL Java_jni_Struct_structSize
      (JNIEnv * env, jobject obj) {
      return sizeof(foo);
    }This is a bit simplistic as foo is static in size (no pointers), but hopefully you get the point.

  • Best way to generate one record per day from a table with eff/exp dates

    Hi,
    Have a table which has various attributes and an eff and exp date. e.g attributea, 01/05/2012, 16/05/2012
    We wish to create another table from this table to have one record per day. e.g 16 records.
    What is best way to achieve this in OWB ?
    Thanks

    Hi,
    Example if have table
    with following contents
    conversion_rate number(6,4)
    EFFEcTIVE_DATE DATE
    expiration_date date
    example record 1.43, 01/05/2012,16/05/2012
    If want to have another table which instead has 16 records one for each day
    e.g
    1.43, 01/05/2012
    1.43,02/05/2012
    1.43,16/05/2012
    Thoughts on best way to do this.
    Thanks

Maybe you are looking for

  • Help! Looking for an iPad app that allows for efficiently filling in PDF forms we create. Know of any?

    I created a quote form for our sales guys to use in the field and we would like them to be able to have the capability to fill it in on their ipads. Is there an app that will let us do the following: Fill in a pripriotary form Click to next field For

  • Multi-Mapping without BPM (Multiples IDoc To one EDI output?)

    Hi all, We are currently working for a client that want us to create, based on a multiple IDoc (an idoc that contains data of more than one idoc) only one output Meaning that we have to do a mapping that based in this multiple input generates only on

  • After updating to IOS 7 I can't see an purchased apps

    After updating to IOS 7 on my iPad 4 when I go to the App Store and click on Purchased, the Purchased tab is completely empty and when I go to the App Store I see the price for the app I already own.  When I click on the price of that app I get eithe

  • Since regrade no increase in Upload Speed? Is this...

    Hi all, My BT Infinity has now been upgraded to the 80/20 service for just over a week. The download speed has doubled from 35 Meg to circa 70 Meg. But the upload speed is stuck at circa 7 Meg, which is good but it hasn't increased from the 40/10 ser

  • Toshiba 24LV411U TV/DVD combo turns off

    I have a Toshiba 24Lv411u TV/DVD combo. When turn it on the red light turns green for about 10 seconds then it turns itself off again. I unplugged it for a few months...went back to it today and it worked fine for a few hours. Now it's back to the sa