From buying a hard disk, the builder mode + VB.net implementation

Source: Internet
Author: User

I am planning to buy a mobile hard drive recently. Do I buy a brand or assemble it? Because it is not very wealthy and there is no such high requirement, buy an assembly. Cheaper.

Recently, I am still looking at the design mode. I think the builder mode is similar to the appearance mode. Therefore, after careful comparison, we will use the builder to buy a hard disk.

First look at the figure:



Let's look at a specific implementation:

Module module1 <br/> sub main () <br/> console. writeline ("boss, I want to assemble a hard disk. ") <Br/> dim D as new ctor <br/> D. givehd () <br/> console. writeline (" BOSS: 'quality is absolutely good... '") <Br/> console. readkey () <br/> end sub <br/> end module <br/> 'first sets up a boss class, that is, Director <br/> public class director <br/> private abuilder as builder <br/> Public sub givehd () <br/> abuilder = new hdbuilder <br/> console. writeline ("small A, get a hard disk box .... ") 'This is added to describe the process and does not need to be added <br/> abuilder. buildparta () <br/> console. writeline ("Small B, get a hard disk core... ") 'This is added to describe the process and does not need to be added <br/> abuilder. buildpartb () <br/> console. writeline (abuilder. getresult) <br/> end sub <br/> end class <br/> 'creates an abstract worker, that is, builder <br/> Public mustinherit class builder <br/> Public mustoverride sub buildparta () <br/> Public mustoverride sub buildpartb () <br/> Public mustoverride function getresult () as string <br/> end class <br/> 'specific worker, that is, entity builder <br/> public class hdbuilder: Inherits builder <br/> private product as new product <br/> Public overrides sub buildparta () <br/> console. writeline ("gives you a hard disk box ..... ") <Br/> end sub <br/> Public overrides sub buildpartb () <br/> console. writeline (" to your hard disk core ..... ") <Br/> end sub <br/> Public overrides function getresult () as string <br/> return product. getresult <br/> end function <br/> end class <br/> 'creates a product class <br/> public class product <br/> Public Function getresult () as string <br/> return "OK, the complete product is for you .... "<Br/> end function <br/> end class <br/> 'creates

Final result:

Boss, I have a hard disk to assemble.

Small A, get a hard disk box ....

Hard Disk box .....

Small B, get a hard disk core...

Hard Disk core .....

All right, the complete product is for you ....

Boss: 'quality is absolutely good... '

After such a process, I don't know if you find it. (If not, let's take a look at my previous blog post on drug purchasing.) The Builder model focuses on the specifications of the entire product process, however, the appearance mode is used to encapsulate a sub-system and provide a unified interface.

The following is a definition of the builder mode:

Builder mode: separates the construction of a complex object from its representation, so that different representations can be created during the same construction process.

In fact, I can add another computer buying process in the process of purchasing hard disks. What should I do if I add a computer buying process?

Let me show you a picture. (Suppose the computer is only composed of a chassis and a display ...)


 

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.