Bridge Mode (Python)

Source: Internet
Author: User

Bridging Mode: Separates the abstract Part of the system from its implementation part so that they can change independently.

BecauseThe target system has multiple levels of classification., Each category will have a variety of changes, so we can separate them from multiple angles and let themIndependent changes,Reduce coupling between them.

# Encoding = UTF-8 ## by Panda # Bridge Mode def printinfo (Info): Print Unicode (Info, 'utf-8 '). encode ('gbk') # Abstract class: mobile phone brand class handsetbrand (): soft = none def sethandsetsoft (self, soft): Self. soft = soft def run (Self): pass # specific abstract class: mobile phone brand 1 class handsetbrand1 (handsetbrand): def run (Self): printinfo ('mobile phone brand 1: ') self. soft. run () # specific abstract class: mobile phone brand 2 class handsetbrand2 (handsetbrand): def run (Self): printinfo ('mobile phone brand 2: ') self. soft. run () # function class: mobile software class handsetsoft (): def run (Self): pass # specific function class: Game class handsetgame (handsetsoft): def run (Self ): printinfo ('running a mobile game') # function class: Address Book class handsetaddresslist (handsetsoft): def run (Self): printinfo ('running a mobile phone address') def clientui (): h1 = handsetbrand1 () extract (handsetaddresslist () h1.run () h1.sethandsetsoft (handsetgame () h1.run () H2 = handsetbrand2 () h2.sethandsetsoft (handsetaddresslist () h2.run () h2.sethandsetsoft (handsetgame () h2.run () returnif _ name _ = '_ main _': clientui ();

Class Diagram:

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.