Wait--that doesn't expose the getters. Hmmmm...

Okay, substitute the interface with a superclass (say, AbstractModel)
that has the getters, but not the setters. Then expose the Model object
as AbstractModel everywhere except inside the Control class.

I've never tried that, but I think it should work. A bit weird, though.

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Mike
Keesey
Sent: Thursday, August 24, 2006 6:46 PM
To: 'Flashcoders mailing list'
Subject: RE: [Flashcoders] Protect model setters from being called by
anyclassexcept Controller

In AS3.0 I think it can be package-private, but until then....

One way is to have the Model class satisfy an interface that lacks the
property (of course, in AS2.0, all interfaces lack properties...), and
then only expose the model class as the interface elsewhere.

interface IModel {
        function anybodyCanUseThis():Void;
}
class Model extends Object implements IModel {
        public function Model() {
                super();
        }
        public function get prop():Object {
                return _prop;
        }
        public function set prop(p:Object):Void {
                _prop = p;
        }
        public function anybodyCanUseThis():Void {
                trace("anybodyCanUseThis()");
        }
        private var _prop:Object;
}
class Control extends Object {
        public function Control() {
                super();
                _model = new Model();
        }
        public function get model():IModel {
                return _model;
        }
        private function doSomethingWithModel():Void {
                _model.prop = "Here we can access the property.";
        }
        private var _model:Model;
}
class SomeOtherClass extends Object {
        public function SomeOtherClass() {
                super();
                _control = new Control();
                _control.model.anybodyCanUseThis();
                _control.model.prop = "This line will cause a compiler
error.";
        }
        private var _control:Control;
}

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Steven
Sacks | BLITZ
Sent: Thursday, August 24, 2006 6:37 PM
To: Flashcoders mailing list
Subject: [Flashcoders] Protect model setters from being called by any
classexcept Controller

Hi,

I have a model class that has a bunch of getters and setters.
Example:

private var _prop:Object;
function get prop():Object {
        return _prop;
}
function set prop(p:Object) {
        _prop = p;
}

I have a controller class that instantiates that model. 

I'm wondering if there is some way to prevent any other class from using
the setter methods of the model except the controller class.  They still
should be able to access the getters.

I want to prevent future developers from being able to access the model
setters from anywhere except the controller in order to enforce proper
MVC patterns.

Thanks!
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to