Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #37029
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Concrete classes considered harmful |
| Date | 2015-07-12 13:20 +1200 |
| Message-ID | <d0dtm9FegarU8@mid.individual.net> (permalink) |
| References | <y42dnfPZC9VKGj3InZ2dnUU78Q-dnZ2d@giganews.com> <d0bfmqFegarU5@mid.individual.net> <aNudncBYS6-M1DzInZ2dnUU78XOdnZ2d@giganews.com> <d0dfehFegarU6@mid.individual.net> <iJadnY_OK46dJzzInZ2dnUU78a-dnZ2d@giganews.com> |
Mr Flibble wrote: > On 11/07/2015 22:17, Ian Collins wrote: >> Mr Flibble wrote: >>> On 11/07/2015 04:09, Ian Collins wrote: >>>> Mr Flibble wrote: >>>>> Dependencies on concrete classes are considered harmful and should be >>>>> replaced with dependencies on abstractions. >>>> >>>> By whom? >>> >>> Go learn the SOLID principles; anyone who does not know and/or follow >>> SOLID is not a very good engineer IMO. >> >> Well I certainly know about them and consider them guidelines, not hard >> and fast rules. If you follow any set of guidelines as if they were >> gospel, you'll end up like the religious zealots who pop up here from >> time to time. >> >> Oh by the way, I also use int in my code, so I guess by your standards >> I'm already not a very good engineer. > > If you lazily use 'int' all over your code.... Which I don't. >>>>> 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. >> >> I've been unit testing everything I write for over a decade now and I've >> yet to encounter problems with non-abstract base classes. Go and and >> learn about mock objects. > > It is virtually impossible to unit test a class that has dependencies on > lots of other concrete classes that themselves require unit testing. The code bases I work on have a mix of abstract and concrete classes. All are TDD projects, so there is effectively 100% test coverage. How would you define "lots of other concrete classes"? most of ours depend on very few others. Having too many dependencies is more of a design issue than having dependencies on concrete classes. > I > know all about mock objects thanks and that is the point: it is easy to > make a class being unit tested use a mock object if that mock object > complies to an abstract interface and is created by a mock object factory. Unless the the class has non-trivial inline member functions, whether it is abstract or not has little bearing on mocking. In this instance, using the Pimpl idiom is just as effective as abstract base classes. Given the three options of abstract, concrete without non-trivial inline member functions or Pimpl classes all are equally simple to mock. I have nothing against using abstract base classes, but in the small embedded world where much of my code is used the cost is often (rightly or wrongly) considered to high a price to pay. -- Ian Collins
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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