-
Notifications
You must be signed in to change notification settings - Fork 761
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new approach for builder pattern #15
base: main
Are you sure you want to change the base?
new approach for builder pattern #15
Conversation
9194068
to
5530529
Compare
5530529
to
5f9beda
Compare
@torokmark, have you checked my suggestion of the changes? :) |
Hi Milad, Nice approach. Though, I am a bit concerned about the followings:
namespace BuilderPattern {
export interface Builder<T> {
build(): T;
}
// ...
}
I would recommend the following here: export class UserDirector implements Director<User> {
constructor(private userBuilder: 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");
}
return this.userBuilder.build()
}
} |
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 a build
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 with get
and setters following Java POJO.
Here, methods should be introduced with set
keyword.
feel free to make suggestion and improvements based on the approach.