For 2023 - 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))
Object Orientation and General technical topics module Q908
Object Orientation: Design Patterns
Exercises, examples and other material relating to training module Q908. This topic is presented on public courses Learning to program in Python
, Object Oriented Programming in PHP
, Python Programming
, Intermediate Python
Design patterns are the way you apply Object Oriented code in a standardised
way to common techniques across a wide range of different data types.
|Articles and tips on this subject||updated|
|4673||Separating detailed data code from the main application - Ruby example|
In almost every appication, you'll be writing a number of pieces of code that use the same data type. It's tempting initially to write all the detail of the individual fields and attributes of the data into a main program - especially if the application's not very long and you're in a hurry:
|4663||Easy data to object mapping (csv and Python)|
Data files with each line being a record, and a number of 'columns' of information relating to each record on each line are a very common way of information being passed around - in essence a spreadsheet of data. And a sensible way for programs to handle that data is for each row / record to be converted ...
|4626||Singleton design pattern - examples and uses|
A Singleton class is one where you can only create one object of a type, or a second object is really a share of the first. An example in PHP of a Singleton design pattern - [here]. Uses a static (class) variable to flag object creation.
A singleton is especially sueful when you're looking to hold ...
|4581||Thin application, thick objects - keep you main code simple. Example in Ruby|
A suggestion. Write thick objects and thin applications. That's what I did in Ruby towards the end of this week's Ruby Course.
Here's the complete application ...
stations = Station.factory("rstats2014.xyz")
for k in (0...20) do
|4421||How healthy are the stars of stage and screen?|
Very few of them, it would seem, are overweight and many are worryingly thin - rather a different situation you'll find in the UK / US population as a whole. Under a body - mass index (BMI) of around 18 to 20, people are considered to be underweight - and taking a data file of online data, I can calculate ...
|4396||Java Utility class - flexible replacement for array. Also cacheing in objects and multiple catch clauses example.|
In Java, utility class objects are used as flexible alternatives to arrays to hold collections of other obejcts. ArrayLists and Vectors hold an ordered (indexed) set of other objects, but due to the structure used in memory, there's no need to know how many items there are going to be in the collection ...
|4377||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 ...
|4359||How to avoid too many recalculations within an object|
Object Orientation is a wonderful way of segmenting your code - hiding algorithms within objects (encapsulating) so that the user of your code need now realise about / understand the algorithms. But this can mean that the user, unknowingly, runs potentially slow and complex code many times over when ...
|4356||Object factories in C++, Python, PHP and Perl|
Raw materials are converted into a manufactured product in a factory or by a factory procedure, and the sort of product you can make depends on both the raw material that's supplied and on the capability of the factory.
And so it is with Object Oriented Computer Programming - supply raw material ...
|4330||Java - factory method, encapsulation, hashmap example|
Many of the Java examples on our web site that are used to illustrate the utility classes in Java.util are written using String objects as both key and value - however, on the Java course just completed I wrote a somewhat more complex examples to show the relationship between various aspects of the language.
|4325||Learning to program - what are algorithms and design patterns?|
There are common themes for how programming statements are put together to give complete section of code to perform combined tasks. And typically these are putting together building blocks in a similar way to we would do things if we were working something out by hand.
Looking for the maximum value ...
|4096||Perl design patterns example|
For short programs, just a few lines of code in a single block do an excellent job. As the program size increases, some sort of structure such as named blocks of code (sub, def, function, proc, lambda etc) becomes logical. And as the code grows further, you should consider splitting out logic relating ...
|4098||Using object orientation for non-physical objects|
A table, a flower, a dog, a train and the second hand on a clock are all physical objects. And when teaching people about Object Oriented programming, using such things as examples is a real help in getting the concepts across an showing how they're implemented. But objects to further than that too - ...
|4021||Spike solution, refactored and reusable, Python - Example|
The other day, we suffered a gap in service from one of our dedicated hosts and after the event I wanted to go through the server logs to find how long the gap was, and whether there was any unusual activity prior to the outage. Problem was - I was looking in a 60 Mbyte log file with ovr 200,000 records ...
|3843||Caching Design Patterns|
We run a hotel, and sometimes we have a quandry when it comes to room changeover.
Scenario: John Smith checks out of room 4 at 8 a.m. on Thursday, and looking at our booking system, we see that the room's not been booked out again until Saturday evening, as a twin room, for Deborah Williams ...
|3810||Reading files, and using factories to create vectors of objects from the data in C++|
On our C++ courses, we concentrate on objects and object design. But we also take a wider look at topics such as references and templates that go to making the complete language, with sections covering changes to things like file handling from the underlying C language.
I've just added a new example ...
|3716||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 ...
|3608||Design Patterns - what are they? Why use them?|
Object orientation provides a wonderful bag of components, but they need to be linked together to provide a full set of facilities for data handling. And very often that linking together is in a way which can be standardised - along the lines of "you normally do it this way". Such standardised methodologies ...
|2977||What is a factory method and why use one? - Example in Ruby|
How do you create an object? By calling a constructor method, of course.
But ... actually ... there's no "of course" about it. Here's a piece of code from an example I wrote yesterday:
and that call creates an object ...
Whilst you can create ...
|485||North, Norther and Northest - PHP 5 Objects|
Here's a PHP example of calls to PHP methods to return the Longitude North of a place, the more northerly of two objects via an object (dynamic) method, and the most northerly of a whole array of objects via a static function.
$north = $ilike->getlong();
$norther = $ilike->northof($ilike);
|2741||What is a factory?|
A Factory is somewhere that takes raw material, and converts into objects of some value. And so it is in Object Oriented Programming, where a "factory method" takes a chunk of raw material and makes an object out of it. It may differ from a constructor in that we may not know what type of object ...
|2322||Looking for a practical standards course|
I'm a great believer in coding standards. In well commented code. In a good choice of variable names, of code re-use, and of thinking before you write. There are points which I stress on every course, even if the majority of the time I spend is on the actual language. So I should not have been surprised ...
|1224||Object Relation Mapping (ORM)|
Another technical term? Yes - this one is a formal name for how you convert a database into Objects - applicable to any OO language (Perl, Python, PHP, Java ...)
Let's reduce it to basics.
* SQL Tables become object classes
* Table rows each become individual objects
* Individual columns become attributes.
Examples from our training material
|Validate.pm|| Validation of parameters object|
|demo1.php|| caching design pattern|
|pages.py|| Factory for webpage objects|
|runners|| Full OO example / various design patterns in Perl|
|single|| Singleton class in PHP|
|uml2.php|| Factory, Comparator, Object Sort routine|
|umli.php|| Code to illustrate UML examples|
|valerie|| Test and demonstration for Validate.pm|
Some modules are available for download
as a sample of our material or under an Open Training Notes License
for free download from [here]
Topics covered in this module
What are design patterns?
Attributes, properties and accessors.
Factory methods, Comparators, etc.
Printing and serialising.
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule
Well House Consultants specialise in training courses in
. We run
throughout the UK (and beyond for longer courses), and
at our training centre in Melksham, Wiltshire, England.
It's surprisingly cost effective to come on our public courses -
even if you live in a different
country or continent to us
We have a technical library of over 700 books on the subjects on which we teach.
These books are available for reference at our training centre.