A simple interface for an instance

Source: Internet
Author: User
Most of the time, when considering the design rather than coding, the interface is truly clear and clearly shows its principles to you. For example, the computer's motherboard and video card have a Unified Agreement between them. As long as they comply with the PCI extension standard, your video card will certainly be able to be plugged into the motherboard, and can access information from the motherboard. This Convention is the interface. In most cases, in the field of software development, interface design should be a task of system analysts, that is, the task of Team Leader. The Team Leader designs the Schelable interface and Architecture as needed. The programmer codes, develops, tests, and so on based on his Architecture. In fact, you can implement the same or even more complete functions without using interfaces. However, with the interface, the entire design will become clear and clear. In terms of software scalability and reusability, the interface design is even more important. Therefore, understanding and understanding interfaces should be from the design perspective, rather than the encoding perspective.

Appendix: A Sample
Requirement: in an existing Table class, I want to display the following data:
1. Text: displays text.
2. Image Information: displays images.
3. video information: play the video

The design is as follows: interface IDisplayable
{
Void Display (Table table );
}

Public class Text: IDisplayable
{
Public void Display (Table table)
{
// Implements the text display method
}
}

Public class Picture: IDisplayable
{
Public void Disply (Table table)
{
// Implements picture display here
}
}

Public class Vedio: IDisplayable
{
Public void Disply (Table table)
{
// Implements vedio play
}
}

Public class Test
{
Text t = new Text ("Hello ");
Picture p = new Picture ("1.jpg ");
Vedio v = new Vedio ("sample. avi ");
Table table = new Table ();
Table. Add (t );
Table. Add (p );
Table. Add (v );
Table. Show ();

Foreach (IDisplayable disp in Table. Items)
{
Disp. Display (this. table );
}

}

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.