Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mediator Pattern in Javascript

 
Raghubir Bose
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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???

 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this discussion to "OO,Patterns, UML and Refactoring" forum...
 
kundan varma
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Raghubir Bose
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic