This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Mediator Pattern in Javascript" Watch "Mediator Pattern in Javascript" New topic
Author

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
Sheriff

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: 322
Why dont you use a function which will enable /disable control boxes conditionally.
Like function changeLook(condType)
{
If(condType=="Y")
document.getElementById("T1").disabled=true;
else
document.getElementById("T1").disabled=false;

}

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

Thanks,
kundan


SCJP1.4,SCBCD,SCEA,CNA
Failures are practice shoots for success.
Raghubir Bose
Greenhorn

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mediator Pattern in Javascript