Skip to content
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

add factory pattern SimpleAtomicLongMultithreadedTest #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

add factory pattern SimpleAtomicLongMultithreadedTest #30

wants to merge 1 commit into from

Conversation

busylee999
Copy link

Create Runnnable intarfaces for RunTest class using factory pattern

Create Runnnable intarfaces for RunTest class using factory method

static Runnable make(ETestCommand command){

switch (command){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think It's not the better way IMHO, check it please http://www.oodesign.com/factory-pattern.html

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain me your position. I have read text at this link. But I do not see any problems in this implementation.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refer to this part "... This implementation is the most simple and intuitive (Let's call it noob implementation). The problem here is that once we add a new concrete product [Runnable] call we should modify the Factory class. It is not very flexible and it violates open close principle. Of course we can subclass the factory class, but let's not forget that the factory class is usually used as a singleton. Subclassing it means replacing all the factory class references everywhere through the code..."

To make my point clear:

  1. It would be more difficult add new tests, I would need to add a new enum , a case and a runnable implementation and call it, two steps more.
  2. I don't see any benefit.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I told in the discussions forum for mr. Douglas that may be in this case factory pattern is excess. And I just send pull request. Because I really think that it is more clearly and elegant solution than to have several static variables contains Runnable implementation.
What will you do if you will need to add more 10 test runnable implementations? You will add more 10 static variables. I think more flexible to store all implementation in one special place. And it will be easy to extract this class in own class file if it will be huge. It's about benefit.

About 1st point. Consider you want to add new test in realization with static vars. You still need to add new static var. Do you think it is really easier than add new enum item?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants