Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > On choosing classes.

Reply
Thread Tools

On choosing classes.

 
 
Francesco S. Carta
Guest
Posts: n/a
 
      08-12-2010
http://www.velocityreviews.com/forums/(E-Mail Removed), on 12/08/2010 09:05:55, wrote:

> On 8月12日, 下午11時57分, "Francesco S. Carta"<(E-Mail Removed)> wrote:
>> (E-Mail Removed), on 12/08/2010 08:42:57, wrote:
>>
>>
>>
>>> On 8月11日, 下午1時45分, Srinu<(E-Mail Removed)> wrote:
>>>> Dear All,

>>
>>>> This is a unfortunate-problem of everyday life to every programmers.
>>>> What are the simple guidelines to choose my classes for my problem?
>>>> We would like to gather some thumb-rules from our own experience.

>>
>>>> This question arose, when I encounter two very different OOP approach.
>>>> 1. For every word uttered in the requirement, we can write a class.
>>>> 2. Most restrictive approach where it is forbidden to add one more
>>>> class.

>>
>>>> Obviously, the above two approaches are not correct, for they
>>>> represent two extremes.
>>>> Question is now, where shall I stop adding more classes? What are the
>>>> simple guidelines/thumb-rules to choose classes for my problem?

>>
>>>> Here interest is not on any particular type of problem. Guidelines
>>>> need be very generic, applicable to all problems that can better be
>>>> solved with OO technology.

>>
>>>> I will be happy to listen from your own experience.

>>
>>>> Sincerely,
>>>> Srinivas Nayak
>>> If you are looking for a practical guideline to design your class.
>>> There is one inhttp://sourceforge.net/projects/cscall/
>>> The reset rule is in principle very generic, applicable to vast
>>> amount of classes. Note that I mean in principle.
>>> The reset rule is derived from the first rule of designing a class,
>>> i.e. making sure object constructed can be safely destructed.
>>> Try it, don't be fooled by its simplicity,

>>
>> Are you referring to the "Rationale.txt" file within the archive
>> downloadable from the page you linked?


[ please snip out signatures when quoting ]

> Yes, at the end of that file. It is written some time ago.


I see. The file is interesting, though the OP seemed to be looking for
guidelines about when to create classes, not about how to create them,
just for the records.

Never mind, I've posted the above just to point out the exact position
of the resource

--
FSC - http://userscripts.org/scripts/show/59948
http://fscode.altervista.org - http://sardinias.com
 
Reply With Quote
 
 
 
 
Phlip
Guest
Posts: n/a
 
      08-23-2010
On Aug 11, 7:59*pm, "Daniel T." <(E-Mail Removed)> wrote:

> I agree with Victor. Anybody who could explain something like this in
> the standard length of a newsgroup post doesn't know what he's talking
> about.


Write unit tests so you can refactor, then the question is less
important.

A clean design...

- passes all tests
- is clear and readable
- duplicates no definitions of behavior
- minimizes lines, methods, and classes

That stuff could fill many books, but the rubric itself fits one
newsgroup post.

And note the list does not say "Open Closed Principle", "Liskov
Substitution Principle", "Encapsulation is Hierarchical", "Contractive
Delegation", or any other high-level goals. That's why they are goals;
enforcing those simplicity rules should help them emerge.
 
Reply With Quote
 
 
 
 
Richard
Guest
Posts: n/a
 
      08-23-2010
[Please do not mail me a copy of your followup]

Phlip <(E-Mail Removed)> spake the secret code
<(E-Mail Removed)> thusly:

>Write unit tests so you can refactor, then the question is less
>important.


In addition: write the tests first and relentlessly eliminate
duplication and you pretty much end up with the design Phlip
describes.
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://legalizeadulthood.wordpress.com/the-direct3d-graphics-pipeline/>

Legalize Adulthood! <http://legalizeadulthood.wordpress.com>
 
Reply With Quote
 
Phlip
Guest
Posts: n/a
 
      08-23-2010
On Aug 22, 9:02*pm, (E-Mail Removed) (Richard) wrote:
> [Please do not mail me a copy of your followup]
>
> Phlip <(E-Mail Removed)> spake the secret code
> <(E-Mail Removed)> thusly:
>
> >Write unit tests so you can refactor, then the question is less
> >important.

>
> In addition: write the tests first and relentlessly eliminate
> duplication and you pretty much end up with the design Phlip
> describes.


Tx for the bump. Too often when someone posts "What's the best design
to X?" they seem to really post "I have only one chance to get this
design right, because I have no unit tests and can never safely
refactor it..."

I'll be good now!
 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      08-23-2010
[Please do not mail me a copy of your followup]

Phlip <(E-Mail Removed)> spake the secret code
<(E-Mail Removed)> thusly:

>Tx for the bump. Too often when someone posts "What's the best design
>to X?" they seem to really post "I have only one chance to get this
>design right, because I have no unit tests and can never safely
>refactor it..."


I agree. I found I had more personal comfort and freedom once I
started practicing test-driven development. (See
<http://tinyurl.com/ns4bvx> for a tutorial on test-driven development
with C++ and Boost.Test.)

I had fewer bugs. I tended to have more classes, but they were more
focused and had a single well defined responsibility. I had less
duplication. Because my classes were smaller, easier to understand
and had a focused role, I found it easier to reuse them in other
contexts. I also felt that my designs were better, even though I
"evolved" them instead of planning them all out up-front. I still
think ahead and do planning, but not so much all the nagging little
details. I do planning and design ahead in broad strokes and let the
tests tell me the details. The unit tests gave me a sense of
confidence in the changes I had made and I never worried about
checking my code in anymore. In general, life was just better.

It takes a while to get into the test-first rhythm, but its a very
rewarding feeling once you get there.
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://legalizeadulthood.wordpress.com/the-direct3d-graphics-pipeline/>

Legalize Adulthood! <http://legalizeadulthood.wordpress.com>
 
Reply With Quote
 
Nick Keighley
Guest
Posts: n/a
 
      08-31-2010
On 11 Aug, 06:45, Srinu <(E-Mail Removed)> wrote:

> What are the simple guidelines to choose my classes for my problem?

[...]
> 1. For every word uttered in the requirement, we can write a class.


I like this one. Imagine a class for "the" or "and"...



 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      08-31-2010
On Mon, 2010-08-30, Thomas Gagne wrote:
> True, you can't explain it all in a newsgroup post, but I believe many
> make it out to be more difficult than it needs to be, including the books.
>
> I recommend taking a /small/ domain you know well, and building it up
> from scratch. Better if you can do it with someone. If not, find
> someone you can show it to after to get their input.
>
> Personally, the best advice I ever got on OO design came from
> Smalltalkers. There's few-enough of them that most you'll find will be
> better than your average Java or C# programmer (IMO).


Note that the question was originally posted in comp.lang.c++.

I don't doubt that the Smalltalk programmers are good at what they do,
but it seems risky to apply their advice straight to C++ design. They're
very different languages, and what's obviously the right design in one
of them may be a terrible choice in the other.

For example, my C++ designs rely heavily on static type checking and
the lack of cost for creating and using many small objects. My Python
designs look rather different.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Switching between automatic IP address/DNS server, and choosing my =?Utf-8?B?cGpkcnVtbWVy?= Wireless Networking 4 09-08-2005 02:49 PM
Choosing PLL ALuPin VHDL 1 07-28-2004 10:01 PM
choosing between mozilla and netscape WicKeD Firefox 4 01-08-2004 11:26 AM
Help in choosing university for MS-PhD in VLSI Ranjith VHDL 0 11-25-2003 12:31 PM
Need help choosing the right router. Robert Le Feve Cisco 3 11-19-2003 02:31 AM



Advertisments