In main.as there are buttons, a listener and an onClick handler. Here in the handler (built through a switch), different blocks with instructions are designed for each of the buttons. How correctly from the point of view of OOP in ActionScript to organize these blocks? Put in function in body main? Put in functions in a separate class? Write in the handler itself?
1 answer
In my opinion, this is not exactly an OOP question. There is more a question of readability and convenience. I rarely saw that one handler was used for several buttons and it was checked with a switch which button was pressed, most often, each button has its own onButtonStartClick() event listener, onButtonStopClick() example. Although, in some cases it may be advisable to use switch. For a more complete answer, you need more complete information on the task, what kind of buttons, what happens when you press, etc.
- Thanks Ivan for taking the time to my question. Actually I am writing a simple game, 5 buttons in the menu: "Play", "Help", "About the game", "Options", "Exit". All actions are quite simple (the same "Exit" fit one command in the case block. With the items "Help" and "About the game" has become more difficult, made drawing texts into a separate function (I give it the name of the button ) But with the "Play" I realized that the whole logic of the game in a case is something completely wrong to put in. - Azrael
- The truth is, I was already suggested by this option: arrange everything into separate classes based on Sprite and just play with the appearance of one or another sprite. It's right? I just have to do with procedural programming (Pascal + Delphi) and for the time being I don’t quite understand how to build the program structure correctly. - Azrael
- For each button it is better to make your event listener, as I wrote. Read about MVC and other architectural patterns, it can greatly simplify working with the architecture of the application. - Ivan Dembicki
- What to do when someone answered my question? - Ivan Dembicki
|