Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Here is my problem:

I stared to create a e-commerce web sites info collector.

So i created a parser for each site. The parser class is state less.

got methods like:

getItemPrice(WebElement page)
getItemTitel(WebElement page)
getItemDescription(WebElement page)
etc..

while creating a JUnit tests for that , the convince way was to make them static mathods

while creating the next parser for the next page , again , same methods. So it just popped out that an interface of an IItem is required here for future changes and etc.. There for i have a problem to set these methods as static. Which require to create an instance of a state less class which lead to simple factory to create these instance and etc..

I'm not sure rather this Interface causing me too much of an overhead or not.

Any ideas?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I don't think there will be too much overhead when using an interface. You can even argue that the use of static methods could generate more overhead in this case, depending on how much different implementations you want to support and how many methods you need.

When using static methods, you need to have some logic which implementation you have to use, which is basically a big switch statement for every method. This can be simplified by putting a wrapper around all those implementations, but evaluating the same switch statement over and over again for each method you want to call is not really advisable.

With the use of interfaces this will be reduced to just one evaluation of the switch statement (in the factory).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.