Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
Designing a base class and subclasses, and their extension, in C++

My first technical post for 2015 - looking back at some of last year's new C++ examples.

Oh - OK - I'm writing this on 1st January and these examples were written and uploaded yesterday, so they're nothing like as old as it sounds.

On Monday and Tuesday, I wrote classes from scratch and looked at basic design - see [here]. I then added dynamic memory management via the new keyword for heap allocation, and using a vector to store references or pointers to my objects - see [here].

Yesterday, I wrote an example in which in had a base class that contained the common specifications and code for a number of similar types of objects, andthen looked at how that can be extended to provide similar types of objects without code duplication. For the whole course, I was very much stressing Test Driven Development and Behaviour Driven Development, and so my very first piece of code - [here] - provides a test and a specification of the API (application programmer interface) to ensure it compiles. It won't load into a complete program yet.

In the second example - [here] - I have implemented the base class (called "shape") and the subclasses ("ball" and "box") together with "cube" which further derives from "shape". You'll notice how hardly any code is repeated from one section to another, as the common code is shared as far up the tree as possible. Colour and density don't change with the change of shape, so they're in the common code, whereas the volume does change for a ball and a box. The volume for a cube is simply the volume for a box, as a cube (by our definition) is simply the special case of a box.

When working out whether incoming data (from a file, for example) relates to boxes, cubes or balls, some logic is required. Naturally, that logic falls within the class code which is looked after by our data type programmer, rather than by our application programmer who just wants to say "here is some data - please work out what object type it is and make the object for me". I have provided a solution to this requirement in the next program - [here] via a static (class) method called "factory"). Nothing special in that name - it's just a convention as raw material is passed in (an incoming string, for example) and manufactured produce (or, rather, and object) is returned.

Further testing was added in the next stage, using the text harness from previous days ([here] for the code [here] for the test harness headers and [here] for the test harness code. And the final example [here] shows operator overloading in C++ ... that may not have been a logical extenion to my demonstration, but it's a subject needed to be covered on our C++ courses and it fitted in here during the presentation.
(written 2015-01-01)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
C234 - C and C based languages - Further C++ Object Oriented features
  [801] Simple polymorphism example - C++ - (2006-07-14)
  [802] undefined reference to typeinfo - C++ error message - (2006-07-15)
  [831] Comparison of Object Oriented Philosophy - Python, Java, C++, Perl - (2006-08-13)
  [1159] It can take more that one plus one to get two. - (2007-04-22)
  [1819] Calling base class constructors - (2008-10-03)
  [2004] Variable Scope in C++ - (2009-01-22)
  [2005] Variables and pointers and references - C and C++ - (2009-01-23)
  [2576] What does const mean? C and C++ - (2010-01-15)
  [2673] Multiple Inheritance in C++ - a complete example - (2010-03-12)
  [2717] The Multiple Inheritance Conundrum, interfaces and mixins - (2010-04-11)
  [2849] What are C++ references? Why use them? - (2010-07-02)
  [3057] Lots of things to do with and within a C++ class - (2010-11-16)
  [3069] Strings, Garbage Collection and Variable Scope in C++ - (2010-11-25)
  [3124] C++ - putting the language elements together into a program - (2011-01-08)
  [3238] Bradshaw, Ben and Bill. And some C and C++ pointers and references too. - (2011-04-09)
  [3430] Sigils - the characters on the start of variable names in Perl, Ruby and Fortran - (2011-09-10)
  [3509] Operator Overloading, Exceptions, Pointers, References and Templates in C++ - new examples from our courses - (2011-11-06)
  [3982] Using a vector within an object - C++ - (2013-01-19)
  [4366] Changing what operators do on objects - a comparison across different programming languages - (2014-12-26)
  [4559] When do I use the this keyword in C++? - (2015-10-29)

C233 - C and C based languages - OO in C++ - beyond the basics
  [798] References and Pointers in C++ - (2006-07-10)
  [925] C++ - just beyond the basics. More you can do - (2006-11-14)
  [1217] What are factory and singleton classes? - (2007-06-04)
  [1572] C - structs and unions, C++ classes and polymorphism - (2008-03-13)
  [1674] What a lot of files! (C++ / Polymorphism demo) - (2008-06-12)
  [2577] Complete teaching example - C++, inheritance, polymorphism - (2010-01-15)
  [2845] Objects and Inheritance in C++ - an easy start - (2010-07-01)
  [3056] C++ - a complete example with polymorphism, and how to split it into project files - (2010-11-16)
  [3123] C++ objects - some short, single file demonstrations - (2011-01-07)
  [3142] Private and Public - and things between - (2011-01-22)
  [3244] C and C++ - preprocess, compile, load, run - what each step is for - (2011-04-12)
  [3251] C++ - objects that are based on other objects, saving coding and adding robustness - (2011-04-17)
  [3508] Destructor methods in C++ - a primer - (2011-11-05)
  [3811] Associated Classes - using objects of one class within another - (2012-07-21)
  [3979] Extended and Associated objects - what is the difference - C++ example - (2013-01-18)
  [4356] Object factories in C++, Python, PHP and Perl - (2014-12-19)
  [4375] Final examples for 2014 - and a look at our 2015 training course options - (2014-12-31)
  [4560] Variables, Pointers and References - C and C++ - (2015-10-29)

Q908 - Object Orientation and General technical topics - Object Orientation: Design Patterns
  [485] North, Norther and Northest - PHP 5 Objects - (2005-11-04)
  [1224] Object Relation Mapping (ORM) - (2007-06-09)
  [2322] Looking for a practical standards course - (2009-08-05)
  [2741] What is a factory? - (2010-04-26)
  [2977] What is a factory method and why use one? - Example in Ruby - (2010-09-30)
  [3608] Design Patterns - what are they? Why use them? - (2012-02-12)
  [3716] Learning C++ - a design pattern for your first class - (2012-05-02)
  [3810] Reading files, and using factories to create vectors of objects from the data in C++ - (2012-07-21)
  [3843] Caching Design Patterns - (2012-08-20)
  [4021] Spike solution, refactored and reusable, Python - Example - (2013-02-28)
  [4096] Perl design patterns example - (2013-05-20)
  [4098] Using object orientation for non-physical objects - (2013-05-22)
  [4325] Learning to program - what are algorithms and design patterns? - (2014-11-22)
  [4330] Java - factory method, encapsulation, hashmap example - (2014-11-27)
  [4359] How to avoid too many recalculations within an object - (2014-12-21)
  [4396] Java Utility class - flexible replacement for array. Also cacheing in objects and multiple catch clauses example. - (2015-01-16)
  [4421] How healthy are the stars of stage and screen? - (2015-02-09)
  [4581] Thin application, thick objects - keep you main code simple. Example in Ruby - (2015-11-21)
  [4626] Singleton design pattern - examples and uses - (2016-01-20)
  [4663] Easy data to object mapping (csv and Python) - (2016-03-24)
  [4673] Separating detailed data code from the main application - Ruby example - (2016-05-16)

Q909 - Object Orientation and General technical topics - Object Orientation: Composite Objects
  [477] Class, static and unbound variables - (2005-10-25)
  [592] NOT Gone phishing - (2006-02-05)
  [1345] Perl and Shell coding standards / costs of an IT project - (2007-09-11)
  [1348] Screw it or Glue it? Access to Object variables - a warning - (2007-09-12)
  [2170] Designing a heirarcy of classes - getting inheritance right - (2009-05-11)
  [2641] Object Oriented Programming in PHP - (2010-02-19)
  [2865] Relationships between Java classes - inheritance, packaging and others - (2010-07-10)
  [2922] Getting the OO design write - with PHP a example - (2010-08-14)
  [3152] Jargon busting - (2011-01-30)
  [3609] How do classes relate to each other? Associated Classes - (2012-02-12)
  [4394] Philosophy behind object design - and how I applied in to a Java example - (2015-01-14)
  [4450] Deciding whether to use parameters, conditional statements or subclasses - (2015-03-05)


Back to
Well House Consultants, Well House Manor, First Great Western Coffee shop, TransWilts / 2014 web site reports
Previous and next
or
Horse's mouth home
Forward to
What FGW passengers want to talk about / and PHP programming to find out
Some other Articles
Installing Cucumber (Ruby)
Behaviour Driven Development / Ruby and Cucumber
Well House Consultants / Well House Manor - Prices for 2015
What FGW passengers want to talk about / and PHP programming to find out
Designing a base class and subclasses, and their extension, in C++
Well House Consultants, Well House Manor, First Great Western Coffee shop, TransWilts / 2014 web site reports
Test driven development, and class design, from first principles (using C++)
A long and disappointing evening
Template / design pattern for C++ constructor and accessors
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2021: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/4377_Des ... in-C-.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb