The study of Go language learning note---non-intrusive interface design

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Keywords: non-invasive

First we need to know what an intrusion interface is, such as defining the interface person Interface: Fight (), Play (), Zhimaoyi (), Zuofan () method Women Interface: Zhimaoyi (), Zuofan () Method Man Interface: Fight () , Play () method The Classperson class implements all the methods of the person interface
    • In the traditional OO programming language, in order to get a man object, at least write a Classman class to implement the man interface, in order to get a women object and have to write a classwomen class to implement women interface, Similarly, to get a person's object to do so, it is clear that the code is not a high rate of reuse
    • Or so design interface,Fight,play,zhimaoyi,zuofan and other basic interface, man interface inherits from Fight,play interface, women interface inherits from Zhimaoyi, Zuofan interface, This is an intrusive interface design (although not yet, but this is common in traditional oo design, and more complex than this)
the non-intrusive interface of go does not inherit this concept at all:Classperson implementation of the person interface, in fact, Classperson also implemented the Women interface and man interface defined methods, so in go, the following way is legal is also recommended var man man = new (Classperson) var Women women = new (Classperson)
In the traditional OO design, the interface is strong, rather than the intrusion-type interface design is more flexible, more practical, not to be continued ...

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.