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