Question

i went through different questions on SO and was trying to find out what is the best way to design an application .I found that somewhere it was written that we should make the object of the class if it has a state this.

i found on the same page that utilities should be avoided so my question is how to implement the functionality. we can not create object because functionality can have and can not have state. and we can also not use static methods also. then how.

P.S---- my question can be layman bcoz i am newbie trying to learn/implement design patterns so whould be happy if somebody can provide me reading material,links with examples.

i know a bit of design patterns theoretically.

Was it helpful?

Solution

You're reading guidelines and treating them like mandates, which puts you in the impossible position of coding with rules that are too strict.

Guidelines are guidelines, and no more than that. If it's a good idea not to use utility classes, then don't use them a lot. Use them sparingly, where it makes sense.

If it's a bad idea (and it is) to use some global variables, then don't do it a lot. But if you need a static helper classes with a variable or two available to the app, then do it in that case.

Don't treat guidelines as law. Treat them as guidelines, and go against them when it makes sense. You will only gain this knowledge by programming. So start doing it, make mistakes, learn from it, and improve your code as you go. You won't get it done perfectly right from the start.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top