File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes OO, Patterns, UML and Refactoring and the fly likes Mediator Pattern in Javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Mediator Pattern in Javascript" Watch "Mediator Pattern in Javascript" New topic

Mediator Pattern in Javascript

Raghubir Bose
Ranch Hand

Joined: Feb 18, 2006
Posts: 88
This is more of a question to discuss.I do not think that it will ever be asked in SCEA.
The mediator pattern [GOF] says "Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and lets you vary their interaction independently"

I was just thinking can we implement mediator pattern in javascript or DHTML(Client Side).Javascript is also an object based language and supports a lot of object oriented features.If I have a situation like I have a set of text boxes and a set of buttons and condtionally I have to enable and disable them.If I am using a fat client like SWING or even applet, it can be done, but what about javascript.Can we do it at all???

I will meet the fairy queen soon !
Ajith Kallambella

Joined: Mar 17, 2000
Posts: 5782
Moving this discussion to "OO,Patterns, UML and Refactoring" forum...

Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
kundan varma
Ranch Hand

Joined: Mar 08, 2004
Posts: 323
Why dont you use a function which will enable /disable control boxes conditionally.
Like function changeLook(condType)


call this function from your other function
like changeLook('Y');


Failures are practice shoots for success.
Raghubir Bose

Joined: Jan 21, 2003
Posts: 8
sure thing ...we can even pass an html control reference to the function, check the type of the control and make that control enabled/disabled.

I was thinking the intent of the Mediator Pattern is "encapsulate how a set of objects interact together by promoting loose coupling by keeping the objects from directly referring or even contact each other"

Html script consitsts of html controls.So whether the interaction between the HTML controls can be encapsulated by using javascript mediation was my question.

I was thinking whether I can pass HTML event to a javascript mediator, which I think I cannot.What I think I can do is put independent javascript processing functions on HTML events.These javascript functions can do the mediation.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Mediator Pattern in Javascript
It's not a secret anymore!