Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #37039

Re: Concrete classes considered harmful

From Chris Vine <chris@cvine--nospam--.freeserve.co.uk>
Newsgroups comp.lang.c++
Subject Re: Concrete classes considered harmful
Date 2015-07-12 14:21 +0100
Organization Datemas.de http://www.news.datemas.de
Message-ID <20150712142105.30ce2f07@bother.homenet> (permalink)
References (1 earlier) <d0bfmqFegarU5@mid.individual.net> <aNudncBYS6-M1DzInZ2dnUU78XOdnZ2d@giganews.com> <mntj93$n8q$1@adenine.netfront.net> <20150712134630.3f753957@bother.homenet> <atCdnXyn6-UI_j_InZ2dnUU78XOdnZ2d@giganews.com>

Show all headers | View raw


On Sun, 12 Jul 2015 13:54:44 +0100
Mr Flibble <flibble@i42.co.uk> wrote:
> On 12/07/2015 13:46, Chris Vine wrote:
> > On Sun, 12 Jul 2015 11:32:53 +0000 (UTC)
> > Juha Nieminen <nospam@thanks.invalid> wrote:
> >> Mr Flibble <flibble@i42.co.uk> wrote:
> >>>>> A class should not new its
> >>>>> member objects for example but rather should use a factory
> >>>>> passed into its constructor.
> >>>>
> >>>> Why?
> >>>
> >>> Good luck unit testing a class that has lots of dependencies on
> >>> concretions.
> >>
> >> So we should just forget what makes C++ so efficient as it is, and
> >> just turn it into a less-efficient Java/C# variant?
> >>
> >> Unit testing is ok, but I'm not happy if unit testing means that my
> >> program needs to be 10 times slower than it could be, even when
> >> making the final release build.
> >>
> >> (And no, I'm not even exaggerating with that "10 times slower".)
> >
> > It's mocking rather than unit testing as such where the issue tends
> > to arise.  However, there is no need to adopt complicated abstract
> > interfaces on the Flibble model just to provide dependency
> > injection for
> 
> Abstract interfaces are not "complicated"; abstract interfaces are 
> actually simpler than the concrete classes that implement them;
> abstract interfaces allow loose coupling; abstract interfaces are a
> win-win as far as designing, implementing and maintaining software is
> concerned.

Abstract interfaces have their uses, but often best hidden as an
implementation detail behind a concrete class.  std::function is a good
example of this, which is a templated concrete type which happens to use
an internal helper type with a virtual function and inheritance for type
erasure purposes.  (In consequence, the std::function concrete type
enables you to implement the strategy pattern or the observer pattern
without having you write your own abstract interfaces, so improving
design and reducing coupling.)

> The only issue with abstract interfaces is performance
> when using them with C++ (hence the reason for this thread).
> 
> /Flibble
> 

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Concrete classes considered harmful Mr Flibble <flibble@i42.co.uk> - 2015-07-11 04:04 +0100
  Re: Concrete classes considered harmful Ian Collins <ian-news@hotmail.com> - 2015-07-11 15:09 +1200
    Re: Concrete classes considered harmful Mr Flibble <flibble@i42.co.uk> - 2015-07-11 17:49 +0100
      Re: Concrete classes considered harmful Mr Flibble <flibble@i42.co.uk> - 2015-07-11 18:10 +0100
        Re: Concrete classes considered harmful Martin Shobe <martin.shobe@yahoo.com> - 2015-07-11 13:33 -0500
      Re: Concrete classes considered harmful Ian Collins <ian-news@hotmail.com> - 2015-07-12 09:17 +1200
        Re: Concrete classes considered harmful Mr Flibble <flibble@i42.co.uk> - 2015-07-12 01:51 +0100
          Re: Concrete classes considered harmful Ian Collins <ian-news@hotmail.com> - 2015-07-12 13:20 +1200
            Re: Concrete classes considered harmful Mr Flibble <flibble@i42.co.uk> - 2015-07-12 02:32 +0100
              Re: Concrete classes considered harmful Ian Collins <ian-news@hotmail.com> - 2015-07-12 15:48 +1200
                Re: Concrete classes considered harmful Mr Flibble <flibble@i42.co.uk> - 2015-07-12 13:46 +0100
              Re: Concrete classes considered harmful Ian Collins <ian-news@hotmail.com> - 2015-07-12 16:14 +1200
                Re: Concrete classes considered harmful legalize+jeeves@mail.xmission.com (Richard) - 2015-07-13 17:46 +0000
                Re: Concrete classes considered harmful Ian Collins <ian-news@hotmail.com> - 2015-07-14 08:52 +1200
                Re: Concrete classes considered harmful legalize+jeeves@mail.xmission.com (Richard) - 2015-07-13 22:01 +0000
            Re: Concrete classes considered harmful legalize+jeeves@mail.xmission.com (Richard) - 2015-07-13 17:28 +0000
              Re: Concrete classes considered harmful Ian Collins <ian-news@hotmail.com> - 2015-07-14 08:47 +1200
                Re: Concrete classes considered harmful legalize+jeeves@mail.xmission.com (Richard) - 2015-07-13 22:02 +0000
                Re: Concrete classes considered harmful Ian Collins <ian-news@hotmail.com> - 2015-07-14 10:35 +1200
                Re: Concrete classes considered harmful legalize+jeeves@mail.xmission.com (Richard) - 2015-07-14 04:52 +0000
                Re: Concrete classes considered harmful Ian Collins <ian-news@hotmail.com> - 2015-07-14 19:31 +1200
                Re: Concrete classes considered harmful legalize+jeeves@mail.xmission.com (Richard) - 2015-07-15 16:57 +0000
                Re: Concrete classes considered harmful Ian Collins <ian-news@hotmail.com> - 2015-07-16 09:49 +1200
                Re: Concrete classes considered harmful legalize+jeeves@mail.xmission.com (Richard) - 2015-07-16 15:53 +0000
                Re: Concrete classes considered harmful Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-10-08 13:20 +0000
                Re: Concrete classes considered harmful legalize+jeeves@mail.xmission.com (Richard) - 2015-10-12 20:48 +0000
      Re: Concrete classes considered harmful Juha Nieminen <nospam@thanks.invalid> - 2015-07-12 11:32 +0000
        Re: Concrete classes considered harmful Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2015-07-12 13:46 +0100
          Re: Concrete classes considered harmful Mr Flibble <flibble@i42.co.uk> - 2015-07-12 13:54 +0100
            Re: Concrete classes considered harmful Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2015-07-12 14:21 +0100
              Re: Concrete classes considered harmful Mr Flibble <flibble@i42.co.uk> - 2015-07-12 14:40 +0100
                Re: Concrete classes considered harmful Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2015-07-12 14:59 +0100
    Re: Concrete classes considered harmful legalize+jeeves@mail.xmission.com (Richard) - 2015-07-13 17:08 +0000
      Re: Concrete classes considered harmful Mr Flibble <flibble@i42.co.uk> - 2015-07-13 19:59 +0100
      Re: Concrete classes considered harmful Mr Flibble <flibble@i42.co.uk> - 2015-07-13 20:06 +0100
  Re: Concrete classes considered harmful "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2015-07-11 05:11 +0200
    Re: Concrete classes considered harmful legalize+jeeves@mail.xmission.com (Richard) - 2015-07-13 17:10 +0000
  Re: Concrete classes considered harmful "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2015-07-11 06:07 +0200
    Re: Concrete classes considered harmful woodbrian77@gmail.com - 2015-07-11 14:12 -0700
  Re: Concrete classes considered harmful Paavo Helde <myfirstname@osa.pri.ee> - 2015-07-11 02:06 -0500
    Re: Concrete classes considered harmful JiiPee <no@notvalid.com> - 2015-07-11 08:28 +0100
    Re: Concrete classes considered harmful Reinhardt Behm <rbehm@hushmail.com> - 2015-07-11 15:48 +0800
  Re: Concrete classes considered harmful Chris Vine <chris@cvine--nospam--.freeserve.co.uk> - 2015-07-12 00:16 +0100
    Re: Concrete classes considered harmful Mr Flibble <flibble@i42.co.uk> - 2015-07-12 01:52 +0100
  Re: Concrete classes considered harmful David Harmon <source@netcom.com> - 2015-07-12 06:58 -0700
    Re: Concrete classes considered harmful Mr Flibble <flibble@i42.co.uk> - 2015-07-12 15:45 +0100
  Re: Concrete classes considered harmful Mr Flibble <flibble@i42.co.uk> - 2015-07-12 16:30 +0100
    Re: Concrete classes considered harmful woodbrian77@gmail.com - 2015-07-12 11:23 -0700
      Re: Concrete classes considered harmful "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2015-07-12 21:37 +0200
        Re: Concrete classes considered harmful woodbrian77@gmail.com - 2015-07-12 14:34 -0700
      Re: Concrete classes considered harmful Luca Risolia <luca.risolia@linux-projects.org> - 2015-07-13 00:38 +0200

csiph-web