object-oriented actionscript 3.0

20
4th-6th June 2008 Edinburgh, Scotland Object-Oriented ActionScript 3.0 Peter Elst

Upload: peter-elst

Post on 22-Apr-2015

7.162 views

Category:

Technology


2 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Object-Oriented ActionScript 3.0

4th-6th June 2008Edinburgh, Scotland

Object-Oriented ActionScript 3.0

Peter Elst

Page 2: Object-Oriented ActionScript 3.0

4th-6th June 2008Edinburgh, Scotland

Object-Oriented Programming

■ Difficult■ Scary■ Overhead■ Only for large teams

Page 3: Object-Oriented ActionScript 3.0

4th-6th June 2008Edinburgh, Scotland

Object-Oriented Programming

■ Difficult? Structured code■ Scary■ Overhead■ Only for large teams

Page 4: Object-Oriented ActionScript 3.0

4th-6th June 2008Edinburgh, Scotland

Object-Oriented Programming

■ Difficult? Structured code■ Scary? Initial learning curve■ Overhead■ Only for large teams

Page 5: Object-Oriented ActionScript 3.0

4th-6th June 2008Edinburgh, Scotland

Object-Oriented Programming

■ Difficult? Structured code■ Scary? Initial learning curve■ Overhead? Promotes code reuse■ Only for large teams

Page 6: Object-Oriented ActionScript 3.0

4th-6th June 2008Edinburgh, Scotland

Object-Oriented Programming

■ Difficult? Structured code■ Scary? Initial learning curve■ Overhead? Promotes code reuse■ Only for large teams? Useful for anyone

Page 7: Object-Oriented ActionScript 3.0

4th-6th June 2008Edinburgh, Scotland

Classes (the artist formerly known as prototype)

■ The way things were:

function Conference() { this.name = "Flashforward";}

Conference.prototype.getName = function() { trace("conference name: "+this.name);}

var myConference = new Conference();myConference.getName();

Page 8: Object-Oriented ActionScript 3.0

4th-6th June 2008Edinburgh, Scotland

Classes (the artist formerly known as prototype)

■ The way things are:

package { public class Conference { public var name:String = "Flashforward";

public function getName():void { trace("conference name: "+this.name); } }}

Page 9: Object-Oriented ActionScript 3.0

4th-6th June 2008Edinburgh, Scotland

Instances

■ Classes provide a blueprint■ Instances set their values for properties

Page 10: Object-Oriented ActionScript 3.0

4th-6th June 2008Edinburgh, Scotland

Inheritance (getting rich the easy way)

■ Classes can extend each-other■ Avoids code duplication■ Properties and methods can be overridden

package { public class SuperClass extends BaseClass { public function SuperClass() { super(); } }}

Page 11: Object-Oriented ActionScript 3.0

4th-6th June 2008Edinburgh, Scotland

Inheritance vs composition

■ Inheritance deals with an is a relationship■ Composition is used for has a relationships

Employee is a Person Employee has a Job

Page 12: Object-Oriented ActionScript 3.0

4th-6th June 2008Edinburgh, Scotland

Encapsulation (don't touch my stuff)

■ Protect the inner workings of your code through the use of access modifiers

■ Provide an API for other classes to use by providing getter/setter methods

public - anything can access this private - only the class itself can access protected - class and its subclasses can access internal (default) - all classes in the same class package

Page 13: Object-Oriented ActionScript 3.0

4th-6th June 2008Edinburgh, Scotland

Polymorphism (copycat behavior)

■ Have classes use the same method names ■ Allows classes to be swapped at runtime■ Same name but different implementation

Doctor.work() Fireman.work() WebDeveloper.work()

Page 14: Object-Oriented ActionScript 3.0

4th-6th June 2008Edinburgh, Scotland

Interfaces (sign on the dotted line)

■ Classes can use one or more interfaces ■ Interfaces require a class to implement a

specific set of methods■ Used to formalize polymorphism■ Interfaces can extend each-other

Page 15: Object-Oriented ActionScript 3.0

4th-6th June 2008Edinburgh, Scotland

Design PatternsGeneral solutions to common problems

Page 16: Object-Oriented ActionScript 3.0

4th-6th June 2008Edinburgh, Scotland

Observer pattern

■ Problem: notify other classes when an update occurs in a data model

■ Solution: keep an array of all instances that want to be notified and call their update method then the model has changed

Page 17: Object-Oriented ActionScript 3.0

4th-6th June 2008Edinburgh, Scotland

Singleton pattern

■ Problem: allow only one instance of a class to exist in an application

■ Solution: prevent the constructor from being called outside of the class scope and provide a static method for returning the single class instance

Page 18: Object-Oriented ActionScript 3.0

4th-6th June 2008Edinburgh, Scotland

Want to learn more?

Books■ Object-Oriented ActionScript 3.0■ Essential ActionScript 3.0

Course■ Core ActionScript 3.0 (Skills Matter - London)

Page 19: Object-Oriented ActionScript 3.0

4th-6th June 2008Edinburgh, Scotland

Thanks!

Page 20: Object-Oriented ActionScript 3.0

4th-6th June 2008Edinburgh, Scotland

Get in touch!

Peter ElstFlash Platform Consultant

Blog: www.peterelst.comEmail: [email protected]: www.linkedin.com/in/peterelstTwitter: www.twitter.com/peterelst