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)) |

Well House Consultants
You are on the site of
Well House Consultants
who provide
Open Source Training Courses
and business
hotel accommodation. You are welcome to browse and use
our resources subject to our copyright statement and to add in links from your pages to ours.
Other subject areas - resources
Java Resources
Well House Manor Resources
Perl Resources
Python Resources
PHP Resources
Object Orientation and General topics
MySQL Resources
Linux / LAMP / Tomcat Resources
Well House Consultants Resources
Extras Resources
C and C++ Resources
Ruby Resources
Tcl/Tk Resources
Web and Intranet Resources
|
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
Background 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:
fh ... | 2016-05-17 | 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 ... | 2016-03-27 | 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 ... | 2016-01-20 | 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")
stations.sort!
for k in (0...20) do
puts ... | 2015-11-21 | 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 ... | 2015-02-12 | 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 ... | 2015-01-17 | 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 ... | 2015-01-01 | 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 ... | 2014-12-22 | 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 ... | 2014-12-19 | 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.
Using ... | 2014-11-28 | 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 ... | 2014-11-22 | 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 ... | 2013-05-25 | 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 - ... | 2013-05-25 | 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 ... | 2013-03-01 | 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 ... | 2012-08-25 | 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 ... | 2012-08-11 | 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 ... | 2012-05-05 | 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 ... | 2012-02-25 | 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:
sageroll.push Transact::factory(current)
and that call creates an object ...
Whilst you can create ... | 2010-09-30 | 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[17]->getlong();
$norther = $ilike[45]->northof($ilike[41]);
$northest ... | 2010-08-14 | 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 ... | 2010-04-26 | 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 ... | 2009-08-05 | 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.
OK ... | 2007-06-12 |
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 |
Background information
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. Operator Overloading. Printing and serialising. Utility classes.
Complete learning
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule page.
Well House Consultants specialise in training courses in
Ruby,
Lua,
Python,
Perl,
PHP, and
MySQL. We run
Private Courses throughout the UK (and beyond for longer courses), and
Public Courses 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.
|
|
|