Builder of Javascript Design Pattern (4)

Posted by selliott on Wed, 01 Apr 2020 02:30:50 +0200

Creative design pattern builder pattern


The so-called builder mode is the consideration of details. We need to consider the whole and details to build a qualified design. That's our class.
The presentation layer and our infrastructure need to be separated.

case analysis

1. Applicants need to release resumes on our platform
2. Show the job applicant's specialty
3. Hide the personal privacy information and contact information of job seekers

let Person = function(param){
   this.skill = param && param.skill || 'secrecy'this.hobby = param && param.hobby || 'secrecy';
Person.prototype = {
    return this.skill 
    return this.hobby;
let Named = function(name){
  let that = this;
  //Constructor resolves last name and first name of a name 
     that.fullName = name;
     if(name.indexOf(' ') !== -1){
       that.firstName = name.slice(0,name.indexOf(' '));
       that.lastName = name.slice(name.indexOf(' '))
let Work = function(work){
   var that = this;
       case 'CODER': = 'software engineer';
         that.workDescription = 'The world of knitting farmers'
       case 'UI': = 'Graphic Designer';
         that.workDescription = 'Design is always so casual, but it's aesthetic';
       case 'UE':
 = 'Designer';
          that.workDescription  ='Take a different road and share the eternal beauty'
       default: = work;
         that.workDescription = 'Sorry, we don't know the description of the position you chose'
Work.prototype  = {
  changeWork(work){ = work;
    this.workDescription = description;

Create a job seeker

let JobSeeker =function(name,work){
 // Candidates to cache
  let _jobSeeker = new Person();
   // Create job seeker name = new Named(name);
   //Create a job seeker's desired position = new Work(work);
  return _jobSeeker;
let Anna = new JobSeeker('Anna Chen','UE');
console.log( // Anna;
console.log( // Take a different road and share the eternal beauty

All the factory models will eventually get a whole.
Reference book: JavaScript design mode, Zhang Rongming
At the same time, you can also refer to this reader's impressions

Topics: Javascript