Design Mode _ Bridge mode

Source: Internet
Author: User


Bridge Pattern

Decouple an abstraction from its implementation so and the can vary independently. ( Decoupling abstractions and implementations so that the synchronicity can change independently)


Example"The world is're awfully, all for the benefit of the world."reality and structure apartClothing company = "Clothing" + "Company" = "clothing Company" before decoupling is a clothing company, write a corp company abstract class, and then on the line, after decoupling, become "clothing" + "Company", clothing abstraction into the product, and the company abstract for the company, synchronicity can change independently, in the abstract level to achieve decoupling.
Product Abstraction

Company Abstract

Public abstract class Corp {private product product;  Public Corp (Product _product) {  this.product=_product;}  public void Makemoney () {  this.product.beProducted ();  This.product.beSelled (); }}


The house is also a product, isn't it?

public class Home extends Product {@Override public void beproducted () {  System.out.println ("The house produced is such ...");} @Override public void beselled () {  System.out.println ("The house that was produced sold out ....");}


IPod, big up!
public class ipods extends Product {@Override public void beproducted () {  System.out.println ("produced by ipod")} @Overr IDE public void beselled () {  System.out.println ("Production of ipod Sold");}}


Real Estate companies only deal with houses.
public class Housecorp extends Corp. {public Housecorp (house _house) {  super (_house);} @Override public void Makemone Y () {  Super.makemoney ();  System.out.println ("Real estate companies make a lot of money"); }}


Cottage Company What products are sold
public class Shanzhaicorp extends Corp. {public Shanzhaicorp (Product _product) {  super (_product);} @Override Public V OID Makemoney () {  Super.makemoney ();  System.out.println ("I am a cottage, I make money"); }}


Scenario Testing

public static void Main (string[] args) {  System.out.println ("The real estate company is running this Way");  House House=new House ();  Housecorp housecorp=new Housecorp (house);  Housecorp.makemoney ();   System.out.println ();   System.out.println ("The cottage company is running like this");  Shanzhaicorp shanzhaicorp=new Shanzhaicorp (New IPod ());  Shanzhaicorp.makemoney (); }

Look at others cottage companies, what is popular on the production of what, anyway, the price is low, quality is also a little bit of assurance.


AdvantagesAbstraction and implementation separation and expansion capabilities PrecautionsThe main consideration is how to split the abstraction and implement

I'm a rookie, I'm on my way.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Design Mode _ Bridge mode

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.