Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
miladvafaeifard wants to merge2 commits intotorokmark:main
base:main
Choose a base branch
Loading
frommiladvafaeifard:builder-design-pattern-improvement

Conversation

miladvafaeifard
Copy link

feel free to make suggestion and improvements based on the approach.

@miladvafaeifardmiladvafaeifardforce-pushed thebuilder-design-pattern-improvement branch from9194068 to5530529CompareOctober 16, 2018 11:22
@miladvafaeifardmiladvafaeifardforce-pushed thebuilder-design-pattern-improvement branch from5530529 to5f9bedaCompareOctober 16, 2018 13:05
@miladvafaeifard
Copy link
Author

@torokmark, have you checked my suggestion of the changes? :)

@torokmark
Copy link
Owner

Hi Milad,

Nice approach. Though, I am a bit concerned about the followings:

  1. Even though,Build interface is a general type with type param, it requires the implementor class to havesetAge,setPhone,setAddress methods.
    What if I am intended to useBuild with other type paramater likeCar. I cannot use it, since it makes me implementsetPhone inCar, but a car does not have phone number.
    In my point of view,Build is quite misleading in this way.

    Let me suggest the following.

    Let us have aBuild interface with type parameter, and this interface has only one method, likebuild(): T

namespaceBuilderPattern{exportinterfaceBuilder<T>{build():T;}// ...}
  1. Director withUserBuilder parameter in its constuctor is a bit smelly in this way. Why does notmakeUser return aUser?

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
Copy link
Author

miladvafaeifard commentedJun 2, 2020
edited
Loading

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? 😃

@torokmark
Copy link
Owner

@miladvafaeifard , yes please, it would be great if you did refactoring on the approach.

I am always happy to see people contributing. Thank you

@miladvafaeifard
Copy link
Author

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() {
Copy link
Owner

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 {
Copy link
Owner

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.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@torokmarktorokmarktorokmark requested changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@miladvafaeifard@torokmark

[8]ページ先頭

©2009-2025 Movatter.jp