Proxy mode proxies (structural type)

Source: Internet
Author: User
Tags documentation

Reference Documentation:

1. Design mode-the basis of reusable object-oriented software

2.http://blog.csdn.net/hguisu/article/details/7542143 (design mode (11) Agent mode proxy (structural type))


Proxy mode proxies (structural type)

Theory of knowledge, you can refer to the knowledge of the documentation, this blog is just to implement a case.

Structure, see figure:


Call logic, see figure:


Case implementation, which is the first case in the code implementation in the book.

Code implementation:

Point.java:
Package com.rick.designpattern.proxy;

/**
 * Created by MyPC on 2017/6/15.
 */Public
class Point {

    private int textSize;
    private int textcolor;

    Public Point () {
    } public

    int GetTextColor () {

        return textcolor;
    }

    public void SetTextColor (int textcolor) {
        this.textcolor = textcolor;
    }

    public int gettextsize () {

        return textSize;
    }

    public void settextsize (int textSize) {
        this.textsize = textSize;
    }

    Public point (int textSize, int textcolor) {

        this.textsize = textSize;
        This.textcolor = TextColor;
    }
}
Event.java:
Package com.rick.designpattern.proxy;

/**
 * Created by MyPC on 2017/6/15.
 */Public
class Event {

    private int x, y;

    Public Event () {
    } public

    int GetX () {

        return x;
    }

    public void SetX (int x) {
        this.x = x;
    }

    public int GetY () {
        return y;
    }

    public void sety (int y) {
        this.y = y;
    }

    public Event (int x, int y) {

        this.x = x;
        This.y = y;
    }
}
Graphic.java:
Package com.rick.designpattern.proxy;

Import Java.io.InputStream;
Import Java.io.OutputStream;

/**
 * Created by MyPC on 2017/6/15.
 */Public
class Graphic {public

    Graphic () {
    } public

    void Draw (Point point) {
    } public

    void Han Dlemouse (Event event) {
    } public point

    getextent () {
        return null;
    }

    public void Load (InputStream inputstream) {
    } public

    void Save (OutputStream outputstream) {
    }
}
Image.java:
package com.rick.designpattern.proxy;
Import Java.io.InputStream;

Import Java.io.OutputStream;
 /** * Created by MyPC on 2017/6/15.
    */public class Image extends Graphic {private String fileName;

    private point Point;
    Public Image (String fileName) {this.filename = FileName;
        Public Image () {} @Override public void Draw (Point point) {this.point = point;
    System.out.println ("Font size:" + point.gettextsize () + "SP; font color:" + point.gettextcolor ());
    } @Override public void Handlemouse (event event) {Super.handlemouse (event);
    } @Override Public Point getextent () {return point; 
    } @Override public void load (InputStream inputstream) {System.out.println ("Class Image is method load"); } @Override public void Save (OutputStream outputstream) {System.out.println ("Class Image is method
    Save "); }
}
imageproxy.java: 
Package com.rick.designpattern.proxy;
Import Java.io.InputStream;

Import Java.io.OutputStream;
 /** * Created by MyPC on 2017/6/15.
    */public class Imageproxy extends Graphic {private String fileName;
    private image Image;

    private point Point;
        Public Imageproxy (String fileName) {this.filename = FileName;
        Point = new Point (0x000000);
    image = NULL;
    Public Imageproxy () {} @Override public void Draw (Point point) {GetImage (). Draw (point);
    } @Override public void Handlemouse (event event) {GetImage (). Handlemouse (event);
        @Override Public Point GetExtent () {if (null! = point) {point = GetImage (). GetExtent ();
    } return point;
    } @Override public void load (InputStream inputstream) {getImage (). Load (InputStream);
   } @Override public void Save (OutputStream outputstream) {getImage (). Save (OutputStream); Public Image GetImage () {if (null = = image) {image = new image (FileName);
    } return image;
 }
}
Textdocument.java:
Package com.rick.designpattern.proxy;

/**
 * Created by MyPC on 2017/6/15.
 *
/public class TextDocument {public

    textdocument () {
    } public

    void Insert (Graphic Graphic) {
        Graphic.draw (new Point (0x777777));}
}
Client.java:
Package com.rick.designpattern.proxy;

/**
 * Created by MyPC on 2017/6/15.
 *
/public class Client {public

    static void Main (string[] args) {
        textdocument textdocument = new Textdocum ENT ();
        Textdocument.insert (New Imageproxy ("test.txt"));
    }
}


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.