teotigraphix.blog.show()

Flex2 :: Decorator or Interface

Hello,

I am right in the middle of a project that uses a HUGE amount of accessor objects. What do I mean? Well, maybe I am making up terminology but, when you have different types of data you want to be able to nail it down and know what you are accessing.

I am wondering if;

var method:IMethodElement = cursor.current as IMethodElement;
trace(method.signature);

is better than;

var method:Method = new Method(cursor.current);
trace(method.signature);

Both will produce something like;

"public function createChildren():void"

Is it better to create a decorator object around a 'primitive' type Object to access it or when populating the data call;

var method:IMethodElement = new MethodElement();
method.name = name;
method.signature = signature;
...

The last example would have been created in the Analyzer class as the data was getting parsed.

In my mind, both are correct but what about performance? It must take up less memory to create a primitive object at analyzation time that carrying around the weight of a class with methods and properties.

I don't know; If anybody reads this and wants to comment, please do so.

As of now, I am using the interface/class implementation. For some reason though, as I get farther into the project, my mind wants to use a Decorator wrapper.

Why is this?

Peace, Mike

2 Responses to “Flex2 :: Decorator or Interface”

  1. JabbyPanda Says:

    We use interface all along the project.

    Imagine the following event can be emitted by different sources derived from different classes by imlementing the same interface: IPhotoGalleryDataProvider

    ———————–
    class gallery.events.PhotosDPUpdatedEvent extends Event

    public function PhotosDPUpdatedEvent(updateType : String, target : IPhotoGalleryDataProvider) {
    super(DATA_SOURCE_UPDATE_EVENT, target);
    _updateType = updateType;
    }

    ——————

    Сan this be done with decorators?

    public function get updateType() : String {
    return _updateType;
    }

  2. teoti.graphix Says:

    Hi,

    Yeah, decorators are very sly beasts. They are great for some thing and not for others.

    This particular question steams from more of a ‘performace’ idea.

    I use interfaces all the time but, I was wondering if it was faster to wrap something during a parse routine.

    I think I will just test it sometime and see what the speed difference is.

    Peace, Mike

Leave a Reply