Java annotator Mode

Source: Internet
Author: User

Iperson:

/*** @ Author com. Tiantian * @ version Creation Time: 3:43:04 */public interface iperson {public void cando ();}

Person:

/*** @ Author COM. tiantian * @ version Creation Time: 3:44:04 */public class person implements iperson {@ override public void cando () {system. out. println ("I Can Code ");}}

Decorator (parent class of all person decorators ):

/*** @ Author COM. tiantian * @ version Creation Time: 3:44:55 */public class decorator implements iperson {private iperson person; Public decorator (iperson person) {This. person = person ;}@ override public void cando () {person. cando ();}}

Decoratorswim (swim decoration -- add "swim" function for Peron ):

/*** @ Author COM. tiantian * @ version Creation Time: 3:48:54 */public class decoratorswim extends decorator {public decoratorswim (iperson person) {super (person) ;}@ override public void cando () {super. cando (); system. out. println ("I also can swim ");}}

Decoratordraw (draw decoration -- add the "Draw" function for Peron ):

/*** @ Author COM. tiantian * @ version Creation Time: 3:47:29 */public class decoratordraw extends decorator {public decoratordraw (iperson person) {super (person) ;}@ override public void cando () {super. cando (); system. out. println ("I also can draw ");}}

Test:

/*** @ Author COM. tiantian * @ version Creation Time: 3:49:35 */public class test {public static void main (string [] ARGs) {decorator = new decoratordraw (New decoratorswim (new person (); decorator. cando ();}}
Related Article

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.