Happy Programming :)


Hello Robotlegs

you can get more slides on
www.eddie.com.tw/slides

you can get this slide on www.eddie.com.tw/slides

About This Slide

WHO AM I ?

I'm a Flash guy!

I'm 高見龍

a.k.a Eddie or Aquarianboy

Contacts

You can find me in those places (so many places, I know..Orz)
or just google me with keyword "高見龍"

Robotlegs

What's Robotlegs?

What's Robotlegs?

a pure AS3 framework
so you can use it not only in Flex, but Flash.

What? just another framework?

80/20 principle
80% of the problems can be solved with 20% of the API

Learning Resources

Internet Resources

Official Website: Some nice articles: .. and find those awesome people in the Robotlegs core team, then add their blogs to your RSS reader.

Book

Before We step into Robotlegs,
there is something you should know!

Something you should know..

SRP
Single Responsibility Principle

Something you should know..

SRP: "Event class should have ONE job and just do it well"

Something you should know..

Dependency Injection
a.k.a DI

Dependency Injection

"A dependency is just a requirement to use another object."

Dependency: Configuration

"A wants to use B in a read-only style"

Dependency: Cooperation

"A wants to use B through its API"

Dependency: Communication

"A wants to register listeners for messages dispatched by B"

Injection: Constructor Injection

public class UserXMLLoader
{
  public function UserXMLLoader( loadScriptPath:String )
  {
    // constructor
  }
}

// inject!
var userXMLLoader:UserXMLLoader = new UserXMLLoader("http://www.eddie.com.tw");

Injection: Public Property Injection

public class UserXMLLoader
{
  public var loadScriptPath:String;
}

var userXMLLoader:UserXMLLoader = new UserXMLLoader();

// inject!
userXMLLoader.loadScriptPath = "http://www.eddie.com.tw";

Injection: Setter Method Injection

public class UserXMLLoader
{
  protected var _loadScriptPath:String;

  public function setLoadScriptPath(value:String):void
  {
    _loadScriptPath = loadScriptPath;
  }
}
var userXMLLoader:UserXMLLoader = new UserXMLLoader();


// inject!
userXMLLoader.setLoadScriptPath("http://www.eddie.com.tw");

Dependency Injection

public function navigateToURL(request:URLRequest, window:String = null):void


example:
navigateToURL(new URLRequest("http://www.eddie.com.tw"));

Not that difficult, right?
you were probably using DI already

"Automated"
Dependency Injection

Automated Dependency Injection

Injection Point: Asking for something.
Injection Rule: How it should be provided.
Injection Point + Injection Rule = Robotlegs Injection.

Automated DI with metadata [Inject]

// Constructor Injection
[Inject]
public function SomeClass(someProperty:IPropertyType):void
{
  // ..
}

// Public Property Injection
[Inject]
public var someProperty:IPropertyType;

// Setter Injection
[Inject]
public function setSomeProperty(value:IPropertyType):void
{
  // ..
}

Metadata?
doesn't it only can be used in Flex?

use custom metadata in Flash

Something you should know..

MVC
model, view, controller

Something you should know..

image from http://priyangpatel.wordpress.com/

More about Robotlegs

Anatomy of the Robotlegs framework


image from http://www.flickr.com/photos/modern_fred/sets/72157603409508667/

in a Robotlegs application..

MVC + S
model, view, controller, and service

in a Robotlegs application..

Model

Model in Robotlegs..

"I store data and represent the current state of your application.", the Model said.

Model in Robotlegs..


in a Robotlegs application..

Service

Service in Robotlegs..

Service: "I'm the gateway to the outside world!"


in a Robotlegs application..

Model v.s. Service

What's the difference?

"You're both my kids!", Actor said.
Service: "I can get data for Model, but I don't store data!"
Model: "Thanks, I don't communicate with the outside world to retrieve data, but I can keep them."

What's the difference?

"A model is empty without the appropriate service, and a service has no purpose without the models."
"Usually, Service is to load and send data for Model."

in Robotlegs, Model and Service are like..

worst kind of dinner party guest!
They don't listen to others, they only talk!

in a Robotlegs application..

View

in a Robotlegs application..

Views: "We're just the poor little guy acting on the stage, we have no right to talk to the authority directly!"

in a Robotlegs application..

Views are viewable components, they usually have some callable methods(API), which will be call by the Mediator.
Actually they can send(dispatch) their opinions, but have to be translated by the Mediator, and re-send to the shared event dispatcher.

in a Robotlegs application..

Mediator

Mediator in Robotlegs..

Mediator: "I'm a busy guy! I manage communication between your application's view components and other objects within your application."

Mediator is just like a mailman..

Mediator can recieve events from view components, and translate to the shared central event dispatcher.
It can also pick up the messages from the central event dispatcher, and call some Views' API according to diffenent situations.

Mediator in Robotlegs..


Mediator in Robotlegs..

Never put view logic in your Mediators!
Avoid the use of "switch", "for", "for each", "if" statement in your mediators as much as possible.
If you have to, maybe you should stop and think about where the logic should really belongs.

Mediator in Robotlegs..

Keeping your mediator LAZY enough! "Do I have to?" or "Can't someone else do it?"

in a Robotlegs application..

Command

Command in Robotlegs..

Commands represent individual actions that your application can perform. (Don't forget SRP)
Commands are stateless, they execute and die!

Command in Robotlegs..



in a Robotlegs application..

Context

Context in Robotlegs..

Context is at the heart of your application
Application start() here!

the whole picture

the whole picture

Live Coding Time!

Conclusion

WHY MVC?
WHY Framework?
WHY Robotlegs?

Why bother?!

It's all about NEAT !
your code would be well organized and maintainable

Decoupling
Program to interface, not to implementation

where is the best position to place my code?

"Sorry, there's no fixed answer for this!"
You might probably say: "If only your view classes care about this, it belongs in your view layer. If other parts of the application might need to be checked or informed, it’s controller code."

be a good programmer

"You CAN doesn't mean you SHOULD do it."

Do you need a framework?
Do you need Robotlegs?

That depends..

Do you need a Robotlegs?

Just give it a try, your computer won't explode anyway :)

That's it!
Hope you all enjoy it

We just into the Robotlegs, and next time we'll..

Any Question?

#