- Notifications
You must be signed in to change notification settings - Fork769
new approach for builder pattern#15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
new approach for builder pattern#15
Uh oh!
There was an error while loading.Please reload this page.
Conversation
9194068
to5530529
Compare5530529
to5f9beda
Compare@torokmark, have you checked my suggestion of the changes? :) |
Hi Milad, Nice approach. Though, I am a bit concerned about the followings:
namespaceBuilderPattern{exportinterfaceBuilder<T>{build():T;}// ...}
I would recommend the following here: exportclassUserDirectorimplementsDirector<User>{constructor(privateuserBuilder:UserBuilder){}create():User{if(this.userBuilder.Name==='Jancsi'){this.userBuilder.setAge(12).setPhone("0123456789").setAddress("asdf");}else{this.userBuilder.setAge(0).setPhone("xxxxxxxxx").setAddress("xxxx");}returnthis.userBuilder.build()}} |
miladvafaeifard commentedJun 2, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Hi Mark 👋 Your approach makes much more sense to me, hence I completely agree on this. Shall i refactor with your approach in my next commit in this thread with a quick polish? 😃 |
@miladvafaeifard , yes please, it would be great if you did refactoring on the approach. I am always happy to see people contributing. Thank you |
Hi@torokmark, I refactored and polished based on your suggestion. I would appreciate if you could review the change. and provide your thoughts on this. |
return this; | ||
} | ||
getUser() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
As I see,getUser
is not used, and seems superfluous, since we have abuild
method.
this.name = name; | ||
} | ||
setAge(value: number): UserBuilder { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
It is a bit misleading to have getter by declaring withget
and setters following Java POJO.
Here, methods should be introduced withset
keyword.
feel free to make suggestion and improvements based on the approach.