tags:

views:

41

answers:

1

What can I do to structure my application so the code stays manageable as it gets bigger? I am building an application that will be in a certain state which will change depending on how the user interacts with it, and there will be many different states the application can be in. I've tried looking for tutorials/resources, but what I find only covers an application with a couple of modes, whereas mine will have lots of different behaviors.

For instance, you can click on object type A or B, so there can be a different behavior for each. If you hold the mouse down and try to drag one, they will behave differently too. But if you weren't holding your mouse down, that means it's not a drag. It's knowing what mode to move into when X event happens while you're in Y state that has me confused because I don't want to have a massive switch statement that handles everything.

+2  A: 

It's not clear what exactly you mean by 'different modes.'

Lots of people spend a ton of time dreaming up abstract structures, behavioral, and organizational patterns for code. Another term for these concepts is design patterns. Aside from cleanly formatting and documenting your code, these concepts help you keep your code logically and functionally clean and operational.

They are well-known and mainstream because they have been proven to work in many implementations; you won't use all of them on every project, but you will probably start using combinations/variations of them if you want to scale. My advice would be to familiarize yourself with these and then reflect on where a particular pattern would work well in your application/state machine.

EDIT: Response to your edits.

For GUI development, in principle, you want to achieve separation of presentation code, behavior code, and state code. Some patterns lend themselves naturally to this end, for example the Model-View-Controller (MVC) pattern.

Alex
I've edited my question.
JustcallmeDrago
"I am building an application that will be in a certain state which will change depending on how the user interacts with it, and there will be many different states the application can be in" - this is true for virtually every single application. A notable exception is an application that runs underwater with no supervision or maintenance, interacts with nothing, and is powered by hopes and dreams.
Alex
Re-edit. Yes, I know, and I feel bad for asking a question about something that I should be able to find, but I'm just not finding it! If there are good resources about building large applications, point me to them please!
JustcallmeDrago
What language are you using? Are you building a desktop GUI? Designing a website? Creating an auditing console for embedded devices?
Alex
Well, I'm building a web app in JavaScript, but I figured that this concept is applicable to any application.
JustcallmeDrago
The canonical solution for client-side scripting is to use a library like jQuery to manipulate the DOM through selectors, events, callbacks, etc... You may also be interested in jQuery-ui; they're both free and can help you do most of the common things you'd expect to be doing in a browser.
Alex
I can do these common things. It's managing when to do what that I don't understand how to do. I guess I need to learn to code a good "brain" for an application. Or maybe it is as simple as just using a bunch of different callbacks for everything. I don't know.
JustcallmeDrago
I think it might be better to close this question and ask a more detailed question perhaps with a concrete example of what you're trying to do.
Alex
Alright. Thanks for your help
JustcallmeDrago