
-----------------------------------
DrummaBoyFB
Mon Dec 13, 2010 1:50 am

Is This Good Programming Practice?
-----------------------------------
I've got a class called Design 
and in that class you can see that I have all my functions and 
stuff declared inside my class. 

Look Below


 
#include "Design.h"

/* Design::GetClothes (BITMAP *Clothes 

Now I wanted to know if it's good programming practice to put all those functions into one class or 
would it be better to separate them and put them into different classes?

Thanks in Advance

-----------------------------------
wtd
Mon Dec 13, 2010 2:29 am

RE:Is This Good Programming Practice?
-----------------------------------
At a quick glance, it seems there's little reason to be using classes here at all.  Instead, namespaces might be a better fit.

-----------------------------------
DrummaBoyFB
Mon Dec 13, 2010 4:02 am

Re: Is This Good Programming Practice?
-----------------------------------
ok thanks. But a quick question. What are the benefits of using namespaces over classes in certain situations and when do you know when to use a namespace over a class?

-----------------------------------
wtd
Mon Dec 13, 2010 4:19 am

RE:Is This Good Programming Practice?
-----------------------------------
Well, look at the way you use your class.  From what I can see, your constructor simply initializes a set of instance variables.  There are no inputs to the constructor, so those variables are always the same.  None of your member functions seem to modify any of those member variables.

What you seem to have is a set of related variables and functions all grouped into one "thing."  This is exactly what namespaces are intended for.

-----------------------------------
DrummaBoyFB
Mon Dec 13, 2010 4:28 am

Re: Is This Good Programming Practice?
-----------------------------------
ohh ok thank you sooo much :D. I never knew what the purpose of them was until now

-----------------------------------
DrummaBoyFB
Mon Dec 13, 2010 12:31 pm

Re: Is This Good Programming Practice?
-----------------------------------
One quick question. 
Should I put the class inside the namespace? Or do without the class?

-----------------------------------
[Gandalf]
Mon Dec 13, 2010 1:30 pm

RE:Is This Good Programming Practice?
-----------------------------------
That would make your class redundant, because currently you are using your class like a namespace.  Just put it in a namespace.  If, in the future, you make more entities like "Design", then you may want to put them in the same namespace, or not.

-----------------------------------
DrummaBoyFB
Mon Dec 13, 2010 3:42 pm

Re: Is This Good Programming Practice?
-----------------------------------
Ok thanks for the info I really appreciate it :Ds

-----------------------------------
DrummaBoyFB
Tue Dec 14, 2010 7:31 pm

Re: Is This Good Programming Practice?
-----------------------------------
So should I put the namespace in a header file then declare all the stuff in a .cpp file like I do with classes?
Or should I just do everything with a header file?

Because I'm trying to declare variables in the .cpp file but it won't work. 
So I was thinking of just putting everything into a header file but I was wondering if that's good programming practice

-----------------------------------
crossley7
Wed Dec 15, 2010 10:03 am

RE:Is This Good Programming Practice?
-----------------------------------
if you use global variables in your header file, either declare them before you declare the heared file (not ideal) or declare them at the top of the header file, and then they will work in the .cpp file still.

That is my thoughts from my recent usage of header files

-----------------------------------
DrummaBoyFB
Wed Dec 15, 2010 11:52 am

Re: Is This Good Programming Practice?
-----------------------------------
No I'm talking about using namespaces in header files

-----------------------------------
wtd
Wed Dec 15, 2010 2:05 pm

RE:Is This Good Programming Practice?
-----------------------------------
Your namespace should be declared in a header file, but then implemented in an implementation file.

-----------------------------------
DrummaBoyFB
Wed Dec 15, 2010 3:09 pm

Re: Is This Good Programming Practice?
-----------------------------------
So basically just like a class? 
(Sorry for all the questions I'm just trying to understand you better)

-----------------------------------
DrummaBoyFB
Wed Dec 22, 2010 11:32 am

Re: Is This Good Programming Practice?
-----------------------------------
wtd... I re-looked at what you said but if you check in my code I do modify values of my member variables in my functions. 
So should I just stick to classes then?
