Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > General > Best Practices

Reply
 
Thread Tools Rate Thread Display Modes
Old 08-30-2007, 11:13 PM   #1
Flash Gordon
rather be programming
 
Flash Gordon's Avatar
 
Join Date: Feb 2005
Location: City of Angels
Posts: 10,000
Default Hollywood Principle

Hi guys,

Is this a violation of the Hollywood Principle?
ActionScript Code:
var upper:UpperLevel = new UpperLevel(); var lower:LowerLevel = new LowerLevel(upper); lower.foo(); // // package {         public class UpperLevel     {                 public function UpperLevel()         {             //         }                 public function speak():void         {             trace("Hello World");         }     } } // // package {         public class LowerLevel     {                 protected var _instance:UpperLevel;         public function LowerLevel(instance:UpperLevel)         {             _instance = instance;         }                         public function foo():void         {             trace("LowerLeve.foo() called");             _instance.speak();                     }     } }

If not, I'm confused what it really means then.
__________________
I'm old enough to know better and young enough to do it anyway. -- maskedman
Flash Gordon is offline   Reply With Quote
Old 08-31-2007, 10:21 AM   #2
hangalot
lala
 
hangalot's Avatar
 
Join Date: Feb 2002
Location: on the road
Posts: 2,859
Default

this is composition. so in that sense not a problem for the hollywood principle.

the hollywood principle's best indications are template or startegy patterns and it asks you not to call up the chain
__________________
oi poloi
http://www.memorphic.com/news/
hangalot is offline   Reply With Quote
Old 08-31-2007, 06:38 PM   #3
Flash Gordon
rather be programming
 
Flash Gordon's Avatar
 
Join Date: Feb 2005
Location: City of Angels
Posts: 10,000
Default

hm....you mean chain calling how how the Decorator Pattern does?

Think you could give me an example of what you mean?
__________________
I'm old enough to know better and young enough to do it anyway. -- maskedman
Flash Gordon is offline   Reply With Quote
Old 09-03-2007, 10:00 AM   #4
hangalot
lala
 
hangalot's Avatar
 
Join Date: Feb 2002
Location: on the road
Posts: 2,859
Default

you could call it a decorator, but in this exact example you are not adding more functionality to a method of the same name and adding some to it.
here i just see a class composed onto the class you wish to use and you taking functionality from that composed class
__________________
oi poloi
http://www.memorphic.com/news/
hangalot is offline   Reply With Quote
Old 09-03-2007, 06:52 PM   #5
Flash Gordon
rather be programming
 
Flash Gordon's Avatar
 
Join Date: Feb 2005
Location: City of Angels
Posts: 10,000
Default

I don't follow. How do I break the Hollywood Principle?
__________________
I'm old enough to know better and young enough to do it anyway. -- maskedman
Flash Gordon is offline   Reply With Quote
Old 09-04-2007, 10:04 AM   #6
hangalot
lala
 
hangalot's Avatar
 
Join Date: Feb 2002
Location: on the road
Posts: 2,859
Default

you don't. the problems i see relates to the fact that you aren't coding to an interface
__________________
oi poloi
http://www.memorphic.com/news/
hangalot is offline   Reply With Quote
Old 09-04-2007, 10:25 AM   #7
Flash Gordon
rather be programming
 
Flash Gordon's Avatar
 
Join Date: Feb 2005
Location: City of Angels
Posts: 10,000
Default

LoL.....I'm not asking for feedback on what I wrote. I'm asking for someone to demonstrate breaking the Hollywood Principle. I don't understand what it is, so I'd like to see the anti-principle in action and then maybe the correct way.
__________________
I'm old enough to know better and young enough to do it anyway. -- maskedman
Flash Gordon is offline   Reply With Quote
Old 09-11-2007, 06:42 PM   #8
Flash Gordon
rather be programming
 
Flash Gordon's Avatar
 
Join Date: Feb 2005
Location: City of Angels
Posts: 10,000
Default

Can anyone show me the correct way of the Hollywood Principle and then the wrong way of it?
__________________
I'm old enough to know better and young enough to do it anyway. -- maskedman
Flash Gordon is offline   Reply With Quote
Old 09-26-2007, 06:22 PM   #9
Assertnfailure
as[org].addListener(this)
 
Assertnfailure's Avatar
 
Join Date: Dec 2005
Location: LA, California
Posts: 838
Default

Which one's the hollywood principle? Know only your friends?
I never hear the names of those principles outside of that java book.

If so, then an example of that violation is:
ActionScript Code:
myShape.graphics.clear()


Of course, nobody really cares about that one, since it would be far too inconvenient to do anything else.

The idea is, that instead of talking to an object's sub-objects directly, you talk to them via the object as proxy. This way you abstract the implementation, so you can make changes in the future without breaking everything.

For example, what if, for some obscure reason, Adobe decides to change the graphics property to "gfx"? Then the example listed above would break all over the place.

However, if instead, your myShape had a public method:
ActionScript Code:
public function clearGraphics():void{ this.graphics.clear(); }

Then you can just call that method instead. If graphics is changed to gfx, then the only place you have to make that change is inside that method...as opposed to a potentially infinite number of places.
Assertnfailure is offline   Reply With Quote
Old 09-26-2007, 07:02 PM   #10
Flash Gordon
rather be programming
 
Flash Gordon's Avatar
 
Join Date: Feb 2005
Location: City of Angels
Posts: 10,000
Default

Ah....that makes total sense. **light bulb goes off** And in fact, it is kind of similar to an adapter or command principles.

According to the book (which I don't have any more) the Hollywood Principle states "Don't call us; we'll call you."

EDIT:
Hmm....here it is at WIKIPEDIA. It seems like composed objects should not call methods on the client.
__________________
I'm old enough to know better and young enough to do it anyway. -- maskedman

Last edited by Flash Gordon; 09-27-2007 at 06:38 PM..
Flash Gordon is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Strong Flash Designer, Hollywood, CA OSS Projects and Positions 0 05-15-2006 09:38 PM
Josh Davis Creative workshop /Toronto and Hollywood pucknell General Chat 0 07-15-2005 07:14 PM


All times are GMT. The time now is 07:46 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.