|
|
| Hi everyone, I'm having a bit of a design problem and want a bit of advice. A have a class called Product. On that class I have three functions, getById, getByName and getByDate. As the project goes developers keep adding functionality to the class, getByDateAndId() ... etc Soon the class has loads of functions in it and it's unmaintainable So what can I do to stop that happening? |
| Peter Pitt, try to use Decorator pattern |
| Use interfaces. |
| Klimapol, how would that stop my classes getting bloated? |
| They'll start to encourage better behaviour. |
| Klimapol, does't matter, I've just realised I'm not that stupid indeed Klimapol, they do do that but it would stop a developer adding a new function, thus the classes getting bloated S/would/wouldn't/ plantino, so basically add a wrapper class which gets bloated but doesn't mess up my original class |
| Peter Pitt, it is depends on what you want |
| what I really want is for new functionality not to make my class unmaintanable |
| Peter Pitt, unmaintainable ? could you provide more info ? you can extract interface or use facade ... |
| Well when I implement Product it'll be clean and short (maintainable). As time goes by my boss is going to as for, say a list of Products order by Date which are red, so the developer that's doing that will create get(colour, 'date') So that's another function I'm worried about lots of functions appearing in my class and it becoming 1 million lines long Thus, unmaintanable Or am I worrying about nothing? |
| Peter Pitt, Private or public methods? |
| Peter Pitt, you might want to look into refactoring your class in that case |
| Klimapol, public kadamat, how? |
| Move the responsabilities for the ordening of the productlist to another class. |