Design Patterns within and outside AGS

Started by LostTrainDude, Thu 26/06/2014 14:40:35

Previous topic - Next topic

LostTrainDude

I really hope that this is the right place to post this.

I'm mostly self-taught and I've been on and off programming\scripting for few years now. Today, for the first time ever (or, at least, so I think), I laid my eyes on the "Design Patterns" topic. Singleton, Factory Method, and so on: I've never actually studied them and what most bothers me is that I really don't understand if, by any chance, I did use any of these patterns without even noticing it.

I'm more or less "accustomed" to the programming vocabulary, still I seem not to make heads nor tails of what I read here.

Lately I've been able to really improve my understanding of programming thanks to practical application of programming concepts through, of course, Adventure Game Design (:D), Music Programming and so on. I think that I'm still in that phase where I really need to "see" things before I can learn them.

So my questions are: what's the story with Design Patterns? Being AGS semi-object-oriented means that can handle them somehow? Can anybody show me some practical use of these patterns? Have you ever used them in AGS?

Thanks in advance! :)
"We do not stop playing because we grow old, we grow old because we stop playing."

Snarky

A design pattern is essentially a standard, off-the-shelf way to solve a particular type of problem. The idea is that in programming, the same issues come up again and again, so knowing a good, standard way to solve them is very useful.

Design patterns are not limited to object-oriented programming (though the concept is perhaps most popular among object-oriented programmers), they exist in every programming language. You're definitely using some already, probably without thinking of them as such.

For example, if you have a bunch of variables that are all alike and related to each other, which you sometimes have to deal with as a unit, and which have some natural order, you put them in an array, right? So an array is a design pattern for dealing with that particular type of "problem". And if you want to apply some processing to every individual variable, you'd probably write a for loop looking something like for(int i=0; i<array.size; i++) {}. (Well, that's how you'd do it in C. In AGS Script you currently have to use a while loop, but it's the same general idea.) So that's a standard design pattern for that task.

Even functions, structs, objects, pointers, and many other programming concepts can be considered design patterns (you'll see that the page you link to lists "null" as a design pattern). As these examples show, many design patterns are built into the programming language. Others you have to implement yourself. (Exactly which ones are built-in depends on the language. AGS has built-in event handlers for things like on_mouse_click(), which is a design pattern you have to implement yourself in many other languages. Timers are another design pattern: AGS has them built in, but you could also implement your own pretty easily.)

Most of the examples on the page you link are probably not that useful in AGS, because the lack of pointers to non-predefined structs makes them too much work to implement. But I've used a few of them in trying to implement a turn-based RPG battle system. (As one specific example, I used "Command" to encapsulate queued actions waiting to be executed.) However, there are no doubt many adventure-game-specific design patterns people could share â€" in fact, some of the articles in various tutorials and on the Wiki are arguably about design patterns.

LostTrainDude

Quote from: Snarky on Thu 26/06/2014 15:23:26
So an array is a design pattern for dealing with that particular type of "problem". And if you want to apply some processing to every individual variable, you'd probably write a for loop looking something like for(int i=0; i<array.size; i++) {}.

Thanks, indeed :) Actually I had a feeling that arrays and functions were design patterns (and it figures, completely) but wasn't sure enough. This whole matter, by the way, gives me further light over things such as engines and SDKs

Quote from: Snarky on Thu 26/06/2014 15:23:26
some of the articles in various tutorials and on the Wiki are arguably about design patterns.

I should definitely check them. Thanks a million for the thorough answer, it really shed some light :D
"We do not stop playing because we grow old, we grow old because we stop playing."

Monsieur OUXX

LostTrainDude: if you really want to use design patterns in AGS, you may try the Lua plugin.
 

SMF spam blocked by CleanTalk