Re: Where to put user interface

From: Greg Comeau (comeau_at_panix.com)
Date: 12/12/03


Date: 12 Dec 2003 09:47:26 -0500

In article <JKidnSzIhtZnJESiRVn-jw@comcast.com>,
Gary Labowitz <glabowitz@comcast.net> wrote:
>I've been seeing more and more students putting cout/cin statements in
>constructors to get the data needed to build an object. This is even though
>I have told them that the I/O should be done in the application and then
>used to create an object initialized with the arguments from the I/O.
>It's falling on deaf ears.
>Is it so natural to think of constructing an object by asking for the
>information?
>Thoughts on this design?

Actually, it is a natural'ish process, or else so many would
not be doing it. That said, it can be circumvented.
It sounds like you are their instructor? It doesn't
always help to just say "don't do that!". I would
suggest at least having them hoist such code into
a member function (so they can see the work IF IT IS
NECESSARY AT ALL can be done elsewhere and in the worst
case the ctor can call it), reviewing lightweight ctors
with them, having them avoid cin and cout specifically
in the class (since I/O could be to some other files),
going over homework in detail, painful detail, spend
hours if necessary, formally integrating and designing
the homeworks into the curriculum. That provides
a feedback circuit, a forum for alternatives to be
explored, for problems to be discussed and debated, etc.
You can also require that the classes change its state
through it's life, so they can see things always just
don't happen at construction time. This ties into a
whole slew of design issues they either may not be
aware of, or can't grasp. It helps if the assignment
is not toy'y too and as real as it can be made.
There's lots to say here, but I'll leave it at that for now.

-- 
Greg Comeau/4.3.3:Full C++03 core language + more Windows backends
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?


Relevant Pages

  • Re: Classes derived from ServicedComponent do not support constructors with arguments?
    ... You have to be careful when you design this stuff as well. ... if you are going to use transactions, or just in time activation, or object ... implementations, with default, parameterless constructors. ... Classes derived from ServicedComponent do not support ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Many questions about partially constructed objects !!!???
    ... I agree with your story and design decisions etc. ... problems because constructors are a bad place to have problems as this ... When the constructors fails the whole ... only common framework is delphi's constructor/destructor framework. ...
    (alt.comp.lang.borland-delphi)
  • Re: [Class]Ridiculous question
    ... These schools of thought are not opposite or immiscible but rather complementary and both can be used in the same design. ... aa.setIndexation(sosaRoot2); ... On the other side of the coin there is something called POJO. ... There are also a myriad of configurations available for the average Swing object, which would require a confusing myriad of constructors to support if they went the POJO route, so again Beans win here by virtue of simplicity. ...
    (comp.lang.java.help)
  • Re: Constructor inheritance
    ... because we often don't want the same set of constructors on derived ... :> Inheritance is supposed to promote code resuse. ... a much more preferable OO design is to instantiate a Thread ... :> So it was surprising the compiler generates missing default constructors. ...
    (comp.lang.java.programmer)
  • Where to put user interface
    ... I've been seeing more and more students putting cout/cin statements in ... constructors to get the data needed to build an object. ... I have told them that the I/O should be done in the application and then ...
    (alt.comp.lang.learn.c-cpp)