Could anyone give me a good use case for ActionScript dynamic classes?
Because it really looks like a bad pratice, for me, in every case.
Anything that uses Proxy must by extension be dynamic. I use Proxy fairly regularly; for example, here's a replacement syntax for ExternalInterface using Proxy.
URLVariables, for example.
You could store the data in a dictionary / object / array too, but you don't gain much in this case, I think, and you cut down some boilerplate.
Well you could use an Object object, but using a dynamic class ensures that it is typed. That's the way I see it, and it's the only reason I would use them. What Juan Pablo is saying is a good reason too.
Related
Can you confirm if I'm on the right track here?
As far as I know, according to http://www.cocos2d-x.org/wiki/Data_Structures
use Vector<T> in place for deprecated __Array or CCArray.
use Map<T> in place for deprecated __Dictionary or CCDictionary.
use Value in place for deprecated __Integer, __String, etc
Is this right?
Also, what's the difference between __ and CC?
xcode tells me CCArray, CCDictionary, etc are deprecated, but when I use __Array or __Dictionary, it doesn't.
yes you are in the right track. but make sure you don't confuse the cocos2d vector with std vectors. They are different. The link you have explains pretty much all you need to know about them
The term CC used to be applied before all the class names to indicate that they were part of Cocos2d. Infact if you look at the header files they still named CC. They changed the namings on these classes so they don't have CC in front of these clases anymore. I am not entirely sure why they had to make such changes but you might get errors here and there because of these changes if something else uses the same class name in your project. As long as if you use the namespaces you won't have trouble. for example instead of Vector you might need to do cocos2d::Vector to indicate you ment to use cocos2d vector instead of the std::vector.
There is a * in the path of the following URL. Does it have special purpose?
...
Thanks
The most probable explanation is that some kind of parsing is taking place using javascript. Where did you find that?
If i'm correct it is called URLmapping, it uses some kind of framework to fill in the asterisk with dynamics
I guess the answer is yes, but what’s the easiest way to do it? I use Template::Toolkit::Simple, if that makes a difference.
I don't think so, but since it's based on a template - just make your template pretty printed.
If you want to create pretty-print HTML then you have to use Template::Plugin::HTML instead of Template::Toolkit::Simple.
You may also try these approaches: Template::Flute and Markapl
Disclaimer: I'm trying to learn proper OO programming/design, so I'm pretty new to this stuff.
I guess this is a general design patterns question, but I'll base my example on a game engine or something that renders objects to the display.
Consider the following:
hierarchy http://img31.imageshack.us/img31/9633/diagrame.png
How can this sort of separation between physical objects (e.g., cubes, spheres, etc.) and the rendering mechanism be achieved in an extensible manner?
This design is not set in stone, and perhaps I've got something wrong from the start. I'm just curious as to how a problem like this is solved in real world code.
That would be the Adapter pattern, or it could be implemented as a Strategy pattern.
The renderer should not be extended by the objects which he is supposed to draw. (Just my opinion) an object in your world is NOT a renderer but the renderer uses objects.
So you have maybe:
Interface IRenderer which defines a function draw(BasicObject).
Then your objects just extend BasicObject to be handled by the/a renderer.
As I said just my opinion. :)
Strategy patern it is.
I would use a Visitor pattern here.
Where the Visitor is the renderer and were the Visited is the 3D/Object.
I would also make the 3D/Object a composite.
I have problems with how to design some classes. I have three classes. One superclass, and two subclasses.
One subclass (AnimatedCharacter) is made by flash, and is used to display the object on screen. The other (CharacterPhysics) is made by myself to extend the superclass.
The problem is that the object I use, is of the type AnimatedCharacter, so I can't just put it in a variable of type CharacterPhysics.
What I tried is some sort of Decorator pattern, by giving the object of type CharacterPhysics a reference to the other object. But now I have to override all the methods of the superclass and pass the methodcalls to the reference. Not an ideal situation.
Does someone know how to solve this kind of problem?
alt text http://www.freeimagehosting.net/uploads/7a95f8352c.png
I don't quite understand the purpose of this class structure you describe (the class names confuse me), but in general a few things come to mind that might help you:
Almost always the best solution is to try and rethink your class model by evaluating whether you should for example break up the responsibilities of classes in an alternate way so that you could utilize inheritance and polymorphism in a better way.
"The problem is that the object I use,
is of the type AnimatedCharacter, so I
can't just put it in a variable of
type CharacterPhysics."
If you want to put an AnimatedCharacter into a variable of type CharacterPhysics, the former should extend the latter, or you should have a common interface (or superclass) for both and then type the variable as such. If this is not possible, my opinion is that you should probably try to rethink and refactor your whole class structure, assuming that you have a solid "object-oriented" reason for wanting to do this in the first place ;).
If the above is not possible, there are some other tricks you can evaluate in your context:
The use of mixins can work as a "poor man's multiple inheritance". Derek Wischusen has some examples on how to implement them in AS3 at flexonrails.net.
"Kind of" implementing the decorator pattern with flash.utils.Proxy. The problem with this approach is that you defer a lot of error checking from compile time to runtime, but the good thing is that you don't have to manually write the "proxying" implementations of all of the methods of the "decorated" object, but write just one (callProperty()) instead.
You can interpret a sublass as an instance of a superclass but not vice sersa. Did you state this backwards?
If so, you could use:
vas cp:CharacterPhysics;
...
var ac:AnimatedCharacter = cp As AnimatedCharacter
Off the top of my head, it seems like those 2 should be interfaces which your main class implements