Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Learning C++ - a design pattern for your first class

From today's C++ Course - a new, clear example of a design pattern for a simple class, its headers, and a test harness - [here].

When using an Object Oriented language, design patterns are really useful. Essentially, they're a known and standard way of combining the features of the language in a convenstional way. By using a design pattern, you're going to be writing along the same lines as others have written before, so you'll:
• avoid some common code pitfalls
• find it easier to write your code as it will be familiar
• produce code that's easy for others to pick up and follow later on

My "SimpleClass" design pattern (as I've chosen to call it) shows a class definition, definition of each of the members, and definition of a calling program. It's very much a starting point within the course, and I went on after this example to add:
• private access for member variables, and public accessor functions
• use of this rather than using different names in the constructor
• multiple methods of the same name (I provided several constructors)

Going one stage further, I divided the code into three separate files:
• a header file which defines the API to the class - [here]
• a file which defines all the methods within the class - [here]
• and the test harness - [here].

This is becoming a much more realistic use of a class - with the test program being separated from the detail of how the class works, and the header file in a third place and shared betweenthe two program files we already have, and other programs which choose to make use of our class.

Completing this example - compile and run:

  munchkin:rcpp grahamellis$ g++ -o tabby table.cpp tabletest.cpp
  munchkin:rcpp grahamellis$ ./tabby
  Size of table 1.8
  1200
  Size of table 3.38
  munchkin:rcpp grahamellis$


We offer three different C++ courses - for delegates who haven't programmed before (5 days), for delegates who have programmed before, but not in C (4 days), and for delegates who have prior programming experience in C. See [here]. A public course series ran last week, and the next public course series runs in mid-July - already booking well, but there are still spaces left at all levels. We run private courses as required for single customer groups; as I write, just one week is available in May and you would then be looking forward several months ...
(written 2012-05-02, updated 2012-05-05)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
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)
  [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)
  [4356] Object factories in C++, Python, PHP and Perl - (2014-12-19)
  [4359] How to avoid too many recalculations within an object - (2014-12-21)
  [4377] Designing a base class and subclasses, and their extension, in C++ - (2015-01-01)
  [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)

C232 - C and C based languages - Defining and using classes in C++
  [1925] Introduction to Object Oriented Programming - (2008-12-06)
  [2577] Complete teaching example - C++, inheritance, polymorphism - (2010-01-15)
  [2578] Where are your objects stored in C++? - (2010-01-16)
  [2579] Creating, setting up and using objects in C++ - (2010-01-16)
  [3250] C++ - how we teach the language and the concepts behind the language - (2011-04-17)
  [3721] Naming blocks of code, structures and Object Orientation - efficient coding in manageable chunks - (2012-05-06)
  [3978] Teaching OO - how to avoid lots of window switching early on - (2013-01-17)
  [4129] Simple OO demonstration in C++, comparison to Python - (2013-07-01)
  [4372] Template / design pattern for C++ constructor and accessors - (2014-12-29)
  [4565] Allocation of memory for objects in C++ - Stack v Heap - (2015-10-31)


Back to
Changing face - Filton
Previous and next
or
Horse's mouth home
Forward to
Returning extra results from a function in C
Some other Articles
Melksham ATC - freedom of the town
Strawberry Cream Teas, Well House Manor, Melksham, starting this weekend
Splitting a record into individual data values in C
Returning extra results from a function in C
Learning C++ - a design pattern for your first class
Changing face - Filton
Just 12 winners? Or 371 or more? Town Centres.
Verticals ... last month
Some unpublished and historic pictures - Museum of Melksham
Kiss
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., 2024: 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.info/mouth/3716_Lea ... class.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb