JavaScript [Design Patterns-facade Pattern]

Source: Internet
Author: User

This pattern involves a single class which provides simplified methods required by client and delegates calls to methods O F Existing system classes.

/** * Design patterns-facade Pattern * https://www.tutorialspoint.com/design_pattern/facade_pattern.htm */// Interfacefunction shape () {}shape.prototype.draw = function () {throw "Shape::d Raw () must be overridden";};/ /Implements Shapefunction Rectangle () {shape.call (this);} Rectangle.prototype = new Shape (); Rectangle.prototype.draw = function () {Console.log ("Rectangle::d Raw ()")};/ /Implements Shapefunction Square () {shape.call (this);} Square.prototype = new Shape (); Square.prototype.draw = function () {Console.log ("Square::d Raw ()")};/ /Implements Shapefunction Circle () {shape.call (this);} Circle.prototype = new Shape (); Circle.prototype.draw = function () {Console.log ("Circle::d Raw ()");};    function Shapemaker () {this.circle = new circle ();    This.rectangle = new Rectangle (); This.square = new Square ();} ShapeMaker.prototype.drawCircle = function () {This.circle.draw ();}; ShapeMaker.prototype.drawRectangle = function () {This.rectangle.draw ();}; Shapemaker.Prototype.drawsquare = function () {This.square.draw ();}; function Facadepatterndemo () {this.shapemaker = new Shapemaker ();}    FacadePatternDemo.prototype.main = function () {this.shapeMaker.drawCircle ();    This.shapeMaker.drawRectangle (); This.shapeMaker.drawSquare ();}; var demo = new Facadepatterndemo ();d emo.main ();

  

Output:

Circle::d Raw ()
Rectangle::d Raw ()
Square::d Raw ()

JavaScript [Design Patterns-facade Pattern]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.