3

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.

3
  • 2
    How can we implement which functionality? Are you looking for a design that works whatever the problem is? That doesn't exist. Commented Apr 10, 2013 at 15:41
  • When in doubt - go for object.In General practice - if you are creating any static class , then it is good , that any static function inside static class should not use any parameters/or member outside function scope. Commented Apr 11, 2013 at 1:23
  • 2
    It seems to me that your are fighting with basics. If you can't decide whether something should be an object or there should be a utility class, you are not ready to use the advanced design approaches, as you will not be able to understand whether you are using them in the right context, which is a must, as design patterns are not panacea. I am not saying that you shouldn't read about patterns and try to use them, I am saying that you shouldn't treat them as a law at this stage. Commented Apr 11, 2013 at 7:53

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

2 Comments

The problem with this approach is that, until you force yourself to work completely without a net (of static "stuff"), you won't learn how to properly design without them. I don't know of many people who have learned how to avoid statics who are in a rush to add even a few of them back in.
Note that a newbieo be may not be in a position to quit "cold turkey," but I think the reason so many developers create "big balls of mud" is that someone told them something similar to the above, and they never got past the stage of leaning on statics like crutches.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.