Java mode (simple example)-appearance Mode

Source: Internet
Author: User

// Create a disk interface

package com.waiguan.test;public interface Disk {public void disk();}

// Implementation class for disk Creation

package com.waiguan.test;public class DiskImpl implements Disk {@Overridepublic void disk() {// TODO Auto-generated method stubSystem.out.println("disk");}}

Create a CPU interface

package com.waiguan.test;public interface CPU {public void cpu();}

// Create an implementation class for the CPU interface

package com.waiguan.test;public class CpuImpl implements CPU {@Overridepublic void cpu() {// TODO Auto-generated method stubSystem.out.println("CPU");}}

// Create a computer class to implement disk and CPU interface callback

package com.waiguan.test;public class Computer {public void product() {// TODO Auto-generated method stubCPU cpu=new CpuImpl();cpu.cpu();Disk disk=new DiskImpl();disk.disk();}}

// Creates a test class, which is mainly used to implement the final result and call the product method in the computer class.

package com.waiguan.test;public class Test {public static void main(String[] args) {// TODO Auto-generated method stubComputer com=new Computer();com.product();}}

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.