Revisit the design pattern (ii)--Bridging mode (bridge)

Source: Internet
Author: User
Tags data structures

A. From the tree

Basically everyone knows the concept of tree.

Dig a little deeper. NET essence of people will understand that. NET has an object tree.

People who learn asp.net will surely know that there is a control tree on the web.

Even college students who have only studied data structures to cope with exams will know the concept of tree.

Two. Expand the demand into a tree

Give us an example of the most commonly used Photoshop.

In Photoshop, there are many graphical tools, such as the stars, such as squares, circles, and so on.

In Photoshop, there is no need to say, there are a lot of colors for us to choose from.

So there was the Red Star, the Green Star. Red Square, Green square and so on.

Look at the resulting tree:

Now it's three graphs, three colors, so we're going to declare nine classes, and of course we're not counting the secondary parent classes in the middle process.

If we are now 18 graphics, 12 colors, then we need to write 18*12 class, then add 12 color classes and a total parent class, altogether we need to 12*18+12+1=229 class.

Let's remember that number.

I hope you do not argue with me, we can write color and then dynamically introduced. We are here to assume that there is no color this attribute, but we need to implement it ourselves.

Three. Object explosion

I've already mentioned the word in two design patterns.

Of course, the explosions here are not as scary as the one in the last article.

But we should also improve him in pursuit of perfection.

Then let's start thinking.

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.