Thread: classes

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    196

    classes

    woo,been a while since my last visit,i learned vb.net anyways i was wondering if when your using classes the entire program should have classes?

  2. #2
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    499
    Yes.

  3. #3
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    It doesn't have to. I'm not sure if I get what you mean, but if I have a class called MyClass, are you asking whether every variable has to be of that type?

  4. #4
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    499
    What I meant was, if you're going to use classes, your entire program should be object-oriented. For consistancy's sake.

  5. #5
    Registered User
    Join Date
    Sep 2005
    Posts
    196
    holy crap,on extreme vb i need to wait atleast 3 hours for a view..

    well what i mean is that in vb.net everything thats created has its own class

    also are classes something I should use often in my programs

  6. #6
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    499
    If you're familiar with Object Oriented programming, you should use it. Not that C programming is bad, but it can save you a lot of time, and more importantly, it's practices structured programming.

    And yes, there are a lot of people on the C++ forum.

  7. #7
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    >> And yes, there are a lot of people on the C++ forum.

    And lots of secrets .... but none here

  8. #8
    Registered User
    Join Date
    Sep 2005
    Posts
    196
    lol 91k+ members on vb 21k+ members here i guess this forums just better



    also when should i make a class public?i cant think of a situation where it wouldnt mess up my code..i know i could just use functions but still

  9. #9
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    [looselyspeaking]A public class is essentially a struct[/looselyspeaking], possibly with functions, even though structs can have functions. If you want to, why not. I prefer to use functions, cause otherwise it breaks encapsulation

  10. #10
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    499
    Quote Originally Posted by lilhawk2892
    lol 91k+ members on vb 21k+ members here i guess this forums just better



    also when should i make a class public?i cant think of a situation where it wouldnt mess up my code..i know i could just use functions but still
    I don't use private that much, but use private whenever you need to protect a special variable.... especially if you know it won't be needed very much by other functions. For everything else, use public.

    [offtopic]twomers, do you like my new signature? [/offtopic]

  11. #11
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Quote Originally Posted by joeprogrammer
    [offtopic]twomers, do you like my new signature? [/offtopic]
    I'm glad to see the trend has caught on. I always check people's posts and sigs now! It's compulsive! Shame smilies don't work with it though Better put in something to do with the thread ...
    [ontopic]>>For everything else, use public.

    I don't know, isn't the point of the private space encapsulation??[/ontopic]
    Last edited by twomers; 08-03-2006 at 07:53 PM.

  12. #12
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    My current concept of basic encapsulation is that the class should contain all
    data and methods it needs, and nothing else - code outside the class should
    not "need" to directly access internal data/private methods. Of course, there
    are circumstances when access needs to be given (perhaps it will be more
    efficient), so we have the friend access mechanism. This obviously doesn't go
    into inheritance, but you get the idea.

    >>if you're going to use classes, your entire program should be object-oriented.
    For consistancy's sake.

    Well there's consistancy and there's beating a dead horse - C++ gives you the
    option of using OOP, but it isn't always the best solution - some aspects of a
    program may be well represented by a class, and others might be more
    cumbersome - the trick is to be able to look at your program goals and at each
    particular task, and decide whether you need to use a class, and that it only
    learned with experience. If you want to focus on that, then try writing some
    programs using just functions (C style), and rewriting using OOP. Compare the
    code and look at which representation of the task is best.
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  13. #13
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    Quote Originally Posted by joeprogrammer
    What I meant was, if you're going to use classes, your entire program should be object-oriented. For consistancy's sake.
    sorry, but I disagree quite strongly. Use whatever paradigm fits the problem you are trying to solve. Most of the best C++ programmers actually use a combination of object-oriented, generic and functional programming.

    Some things are better suited as free functions. As an example, have a look at the STL's algorithm functions (e.g. sort(), find(), for_each(), etc). The "traditional" OO approach would've been to declare a base "container" type with sort, find and for_each methods. Instead these are generalised free functions that allow you to use any type that conforms to the interface. Which allows you to use your own container with these functions or even use a C array!

    In short, use classes where appropriate.
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you Initialize all classes once with New?
    By peacerosetx in forum C++ Programming
    Replies: 12
    Last Post: 07-02-2008, 10:47 AM
  2. Multiple Inheritance - Size of Classes?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 11-26-2004, 09:04 AM
  3. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  4. Exporting VC++ classes for use with VB
    By Helix in forum Windows Programming
    Replies: 2
    Last Post: 12-29-2003, 05:38 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM