This content has been marked as final. Show 4 replies
Local to Sydney, and I don't think the beer will fare well in transit.
Anyway, the most important thing to think about in Cairngorm is that it is a design pattern based upon an MVC/MVP approach, with the model being a singleton.
Without a more specific problem, I'll give a basic approach.
You have to seperate everything out into 3 tiers:
1. User Interface
These 3 tiers each perform their own function.
1. User interface
The user interface handles everything that is displayed on screen. You will usually end up with mix of MXML and actionscript components.
The user interface contains display objects, which will call events. The objects are invoked by user gestures. The events hit the front controller, which will invoke tier 2 (Commands).
Commands contain your business logic. (Can be seperated out into delegates, but usually only when you are calling a server for information.)
The business logic will mangle your model's variables, and change their state, which brings us to Tier 3. (Model)
The model is basically a Singleton pattern. It contains all of the variables of the software.
I have seen 2 forms of implementation. The first is to access the model variables directly, and the second is to access them through functions in an attempt to avoid race condition situations, especially if you are dealing with binding.
When a variable changes in the model, the idea is that the particular model variable is bound in your MXML. If it changes, the Setter is called in the particular component, it becomes dirty, and is redrawn with the new state.
So where do you start thinking in this circle?
Wholistically think about the process you are trying to complete.
Here is a simple example on a system of selling widgets (random item) via a Flex shopping cart.
1. User logs in
2. User selects widget
3. User selects quantity and gets a price
4. User adds to cart
?User may go back to step 2?
5. User checks out
6. User pays
Think about every gesture that the user makes.
- User Enters Username (d)
- User Enters Password (d)
- User clicks login (g)
- User Selects widget from a list (g)
- User selects quantity and gets a price
- Select numerical quantity (d, g)
- user Reads Price (b)
- User adds to cart (g)
- User checks out
- User reads list of products (b)
- User removes unwanted products (g)
- User changes quantity of wanted products (d, g)
- User Accepts Order (g)
- User pays
- User reads price (b)
- User enters CC details (d)
- User clicks pay (g)
- System records order completed, ready for administration interface.
So what do the letters in brackets mean?
d - data input by the user
b - data binding -> when the model changes, update the display
g - gesture. When this is clicked, something on the display changes. Usually OK buttons, submit buttons, dynamic drop downs etc.
Each gesture will have its own command.
For instance, you will have a userLoginCommand.
The userLoginCommand will follow these steps:
1. Check if username exists
1.1 if yes, do passwords match?
1.1.1 if yes,
18.104.22.168 authenticate user
22.214.171.124 change viewstate of model to change to next page
1.1.2 if no,
126.96.36.199 display username / password mismatch message
1.2 if no,
1.2.1 display username / password mismatch message
I can't stress enough how important it is to design your app appropriately, or you will run into HUGE problems down the track, and be stuck refactoring your entire program.
Hope this helps!
Thanks so much for the great post bayani!!!
This is exactly the type of information I am looking for. I really appreciate you taking the time to offer your assistance!!!!
I totally agree with you on the need to design the application correctly from the beginning. That is why I have been trying to get my arms around Cairngorm.
Thank you again for your insights! The next beer is on me! Make it a Fosters .
No worries mate.
If you want to know anything else, feel free to contact me by E-Mail. It's a gmail account, and the same username as what is in my post.
Digressing a little, it's quite funny about "Australian Beer". Everyone who's never been in Australia seems to think that Fosters is our best. If you ever get the chance, try a Toohey's, Carlton Draught, or my favourite, the good ol' XXXX (pronounced Four-Ex) Beer.