Classes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • arganx

    #1

    Classes

    I'm new. All of my books when talking about classes always use some
    sort of "database" example, e.g. tracking stock, tracking baseball
    stats, etc.

    I'm trying to think OOP and wonder is there are uses for classes for ME
    to use within my program. In other words a class of ? to help me to do
    ?. I can't see that this would be different than a function, or am I
    completely missing it.

    Any comments, ideas or short examples would be appreciated.

  • Greg Comeau

    #2
    Re: Classes

    In article <1132509446.829 740.202210@g47g 2000cwa.googleg roups.com>,
    arganx <arganx216@yaho o.com> wrote:[color=blue]
    >I'm new. All of my books when talking about classes always use some
    >sort of "database" example, e.g. tracking stock, tracking baseball
    >stats, etc.
    >
    >I'm trying to think OOP and wonder is there are uses for classes for ME
    >to use within my program. In other words a class of ? to help me to do
    >?. I can't see that this would be different than a function, or am I
    >completely missing it.
    >
    >Any comments, ideas or short examples would be appreciated.[/color]

    In many cases you actually _do_ just want a function.
    Note that that focuses often on solely an perspective
    that is algorithmic, simple, and perhaps only a uni-operation.
    Classes tend to focus on types, subsystems, and relationships
    up and down related types, along with their usually
    multiple operations. The question isn't solely just
    can't I just use functions to code up my problems,
    because obviously computer languages have been around
    for a while, and people have been able to provide fairly
    elaborate applications even though those lanuages did not
    directly support OOP. The issue is more of how we can break
    down problems, spell out the interaction and operations
    which need to occur, and best design and model the task at hand.

    Unfortunately, we cannot do your question justice in a NG, however,
    I know you express what many folks wonder, and go through.
    For well thought out ideas, etc I would suggest getting
    the below two books in addition to your current ones.

    I would get Stroustrup's The C++ Programming Language
    (3rd or special edition) and have a look at Chapter 2, 1,
    23, 24, 25. These are issues pretty much never ever discussed
    in many so-called beginner [C++] books, and yet they are
    exactly about what most of it's all about. It's ok if
    you don't get everything on your first read because you
    will have this book for a long time. Better yet, get
    two copies and wallpaper the room with it.

    Similarly, get Koenig and Moo's Accelerated C++. It tends
    to reverse the normal introductory progression from the
    random low-level hen-pecking solutions looking for problems
    approach and throws you right into what it's all about
    such as abstraction, problem solving, class design, etc.

    These two texts are authoritative, to the point, insightful,
    and then some. Neither is particularly an easy read for
    everybody, however, they are spot on where you need to be.

    See http://www.comeaucomputing.com/booklist for isbn info, etc.
    --
    Greg Comeau / Celebrating 20 years of Comeauity!
    Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
    World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
    Comeau C/C++ with Dinkumware's Libraries... Have you tried it?

    Comment

    • osmium

      #3
      Re: Classes

      "arganx" writes:
      [color=blue]
      > I'm new. All of my books when talking about classes always use some
      > sort of "database" example, e.g. tracking stock, tracking baseball
      > stats, etc.
      >
      > I'm trying to think OOP and wonder is there are uses for classes for ME
      > to use within my program. In other words a class of ? to help me to do
      > ?. I can't see that this would be different than a function, or am I
      > completely missing it.
      >
      > Any comments, ideas or short examples would be appreciated.[/color]

      That is, indeed, a significant problem It might help if we knew what field
      you were in. If you are an old-timey programmer, think of a stack, a linked
      list, a tree, a string as a nice repository of handy tools you can pick up
      and use.

      A person who writes simulators could have a random number class that
      provides, a bunch of different distributions. Uniform, Gaussian, Poisson,
      .... and a selection of generators of varying qualities.

      If you are into statistics, you could have classes that do some of the
      common things, standard deviation, chi-square, ... in classes.

      If you are into math you could have a matrix class. And of course, most
      everyone in any of the sciences can use the complex class, which is, more or
      less, built in, to C++.

      I would think an architect could use a window (NOT tm) class, a door class,
      an elevator class.

      Another approach, it may be helpful to think of a class as a mini program
      with a, possibly, very rich interface.


      Comment

      • osmium

        #4
        Re: Classes

        "osmium" wrote:

        <snippage>
        [color=blue]
        > That is, indeed, a significant problem It might help if we knew what
        > field you were in. If you are an old-timey programmer, think of a stack,
        > a linked list, a tree, a string as a nice repository of handy tools you
        > can pick up and use.[/color]

        One thing I forgot to mention. There are a lot of people who will go to
        great lengths to use classes, even when, IMO, the payback is actually
        negative. I think OOP has been grossly oversold, and I wish someone had told
        me that many years ago. I had to figure it out for myself.

        The attitude of many seems to be "I have this great new hammer and I'll be
        damned if I am going to let it just rust away in the toolbox...." OOP and
        classes are far from a silver bullet.


        Comment

        • Ben Pope

          #5
          Re: Classes

          arganx wrote:[color=blue]
          > I'm new. All of my books when talking about classes always use some
          > sort of "database" example, e.g. tracking stock, tracking baseball
          > stats, etc.
          >
          > I'm trying to think OOP and wonder is there are uses for classes for ME
          > to use within my program. In other words a class of ? to help me to do
          > ?. I can't see that this would be different than a function, or am I
          > completely missing it.
          >
          > Any comments, ideas or short examples would be appreciated.[/color]

          Don't think of "objects" as physical objects. Often, it is ideal, but
          often it will lead you astray.

          A class is used to encapsulate some data along with operations on that
          data. You can use it to abstract the implementation of a concept; that
          concept could be anything, but usually it involves state (stored in the
          data, and operated on by the methods).

          As you gain experience with programming you will (hopefully!) learn to
          think in terms of abstractions of concepts - the rest is relatively easy.

          Ben Pope

          Comment

          • arganx

            #6
            Re: Classes

            Thank you all for your comments. It has given me ideas to think about
            and other references to study.

            Comment

            • Eric Chomko

              #7
              Re: Classes

              osmium (r124c4u102@com cast.net) wrote:
              : "osmium" wrote:

              : <snippage>

              : > That is, indeed, a significant problem It might help if we knew what
              : > field you were in. If you are an old-timey programmer, think of a stack,
              : > a linked list, a tree, a string as a nice repository of handy tools you
              : > can pick up and use.

              : One thing I forgot to mention. There are a lot of people who will go to
              : great lengths to use classes, even when, IMO, the payback is actually
              : negative. I think OOP has been grossly oversold, and I wish someone had told
              : me that many years ago. I had to figure it out for myself.

              I agree. I was taught top-down structured programming (Dijkstra et. al.)
              25-30 years ago and have had a difficult time re-thinking in OOP.
              Object-oriented design is fine, but my OOP tends to go back to the old way
              of thinking to the point I said the heck with it.

              I think if you can come up with (a) data structure(s) that can handle your
              application, then the code will come out of that (i.e. think data first
              and code second and your OO approach tends to fall into place).

              : The attitude of many seems to be "I have this great new hammer and I'll be
              : damned if I am going to let it just rust away in the toolbox...." OOP and
              : classes are far from a silver bullet.

              Agreed.

              Eric

              Comment

              Working...