Leveraging OOP

Started by
12 comments, last by bytecoder 18 years, 3 months ago
OP: yes, you can, and it's even quite recommended. You could also use a static hashtable member of Robot to store the strings (indexed by derived class type) and query that table upon creation of a Robot.

bytecoder: in that case I'm afraid I didn't understand your code. Would the following code work as is? And if yes, please explain how the constructor for Medic( ) becomes aware of the name of the file from which to load the graphic.

Robot medic = new Medic( );assert( medic.icon == Image.FromFile( "medic.png" ) );
Advertisement
Quote:Original post by ToohrVyk
OP: yes, you can, and it's even quite recommended. You could also use a static hashtable member of Robot to store the strings (indexed by derived class type) and query that table upon creation of a Robot.

bytecoder: in that case I'm afraid I didn't understand your code. Would the following code work as is? And if yes, please explain how the constructor for Medic( ) becomes aware of the name of the file from which to load the graphic.

*** Source Snippet Removed ***

No, it wouldn't. The Robot class (the model) has absolutely no knowledge of anything other than abstract robot tasks. The ImageView class is what does the rendering based on 1) the robot's position and 2) the image you gave it. To get input from the user or ai, you would have a RobotController class that controls the robot. If you did for some reason want to create more work for yourself, you could create specific RobotXViews that sets the image in the constructor, but my way is shorter and more flexible.
The topic of this thread is on ways to bind a resource (eg. a pair of filenames) to a class in a concise way, based on an existing code framework. Your proposed solution:


  1. Does not bind a resource to a class in any way. You first asserted that I was wrong and that your code did perform this per-class binding. Then, you contradicted that initial statement and said that per-class binding would require the creation of an additional class for each class for which you want to perform the binding — which falls short of the request for a concise solution, as per the original post.

  2. Does not use the existing code framework provided in the original post, and instead proposes a heavy reworking. Your code is also written in another language which the original poster might not understand, and which does not compile (check the number of required arguments for the ImageView constructor). It uses a basic design that is different from that of the original post: Model-View-Controller, a design with which I happen to be familiar, having used it often in the past.


As a consequence, it seems clear enough to me that your proposal is not an acceptable answer to the question and problem described in the original post of this thread. Your implying that I do not know enough to judge your post — directing me to look up the Model-View-Controller pattern — is something I would consider downright insulting if not for the irony of your contradictions in your third post.

Your initial post does offer some good insight by giving an example of Model-View-Controller, which I agree is a very good thing to use. However, you never stated that your purpose of showcasing an alternative design, which was quite different from the meaning of answering the original question that the format of your post (a blob of code with no accompannying explanations) implied. Moreover, you insisted that your post did answer the original question of the thread, which it does not as you seemed to agree later on. Why not simply begin your post with "This does not answer your question, but a better design would be: ...", maybe followed by a short argumentation of why that design is better.

You don't appear to have read the original question (or deliberately chose to ignore it), you do not answer the original question, and instead make an unsupported, unexplained post that, after thorough reading, seems to scornfully throw away the entire work of the original poster and unilaterally replace it with a half-described and crippled design that has no logical relationship whatsoever to the question, but which you appear to put forward as if it was the best thing that happened to man since the AZERTY keyboard; only to follow up by implying that I am a know-nothing idiot who does not see in which way your post helps solving a problem that it (fact) does not solve.
Your participation is not an answer to the problem, only a suggestion for a better design that is completely orthogonal to the problem, so accept that it is only that, and nothing more.

EDIT: one final remark about your allusive statement in your last post.

Quote:If you did for some reason want to create more work for yourself, you could create specific RobotXViews that sets the image in the constructor, but my way is shorter and more flexible.


There are two errors in the above comment.


  1. Consider the following line of code:
    int main( ) { return 0; }

    Neither this line nor your proposal are acceptable solutions to the problem. My proposal is shorter. Therefore, I suggest we do not create too much work for ourselves, so we keep my solution and throw yours away.

    Before saying that your solution is shorter, you should begin by providing an actual solution.

  2. The you could create specific RobotXViews that set the image in the constructor part of your answer has the quite ironic property of being, word for word, what the original poster wants to know how to do. Is this what you call a solution? Commenting on the general design of the code, giving a design of your own that you insist on being superior without supporting your claims, while leaving the original question unanswered?


Great, cool, you won. Your method is the best, shortest, most easily maintained and most easy to write. Here's your medal. Now, stop interfering with the actual answering of the question.
Quote:
# Does not bind a resource to a class in any way. You first asserted that I was wrong and that your code did perform this per-class binding. Then, you contradicted that initial statement and said that per-class binding would require the creation of an additional class for each class for which you want to perform the binding — which falls short of the request for a concise solution, as per the original post.

Per-class binding can easily be done informally using per-instance binding. By creating a separate class you get strict class binding, but you also get more work and less flexibility.

Quote:
Does not use the existing code framework provided in the original post, and instead proposes a heavy reworking.

I didn't force him to use it. I merely presented the method that I would use. If it doesn't fit in with his overall design, he's free to chose a different method.

Quote:
Your code is also written in another language which the original poster might not understand, and which does not compile (check the number of required arguments for the ImageView constructor).

Didn't notice that he wasn't using C++; guess I filtered out the 'public' keywords before the classes. In any event, the code I posted was more of a demonstration than anything. It didn't have to be production quality to get the point across.

Quote:
As a consequence, it seems clear enough to me that your proposal is not an acceptable answer to the question and problem described in the original post of this thread.

That's something only the OP needs to decide. Arguing about what is "acceptable" and what isn't doesn't seem very productive, in my opinion.

Quote:
Your implying that I do not know enough to judge your post — directing me to look up the Model-View-Controller pattern — is something I would consider downright insulting if not for the irony of your contradictions in your third post.

Your direct attack on the "acceptableness" of my post is something I would consider downright insulting, if not for the irony that your post is completely unrelated to the (already solved) question at hand.

Quote:
Great, cool, you won. Your method is the best, shortest, most easily maintained and most easy to write. Here's your medal. Now, stop interfering with the actual answering of the question.

I fail to see how my solution to the problem, even if it might not be completely appropriate for the OP's situation, interferes any more than your post. If you feel that my post was completely off topic and wouldn't help the OP at all, then rate me down; that is, after all, what the rating system is for. Otherwise, I recommend you leave it to the OP to decide what is appropriate and what is not.

This topic is closed to new replies.

Advertisement