Exercises, examples and other material relating to training module Q907. This topic is presented on public courses
This is the third and final module that introduces object orientation, and is applicable to any language with OO support. It is vital that applications are correctly designed from the beginning. Starting from first principles, we take students through the steps of modelling a system using informal methods, and we also introduce more formal methods such as UML.
|Articles and tips on this subject
|Associative objects - one object within another.
A new demonstration of the use of objects within objects - [here] from today's PHP course.
Faced with a class of public transport departure times (as strings) and run times (in pinutes), I added a class of time objects so that I could encapsulate the calculations of time into their own class.
|Spike solution, refactoring into encapsulated object methods - good design practise
Initial test code on new data sets - your research work - will most likely take place in smaller chunks of code while you work out just how the data flows and what you need from it (and you are remembering to read documentation supplied by the data originator, aren't you??).
But having done that initial ...
|The spirit of Java - delegating to classes
Building up towards the end of a Java course, I've been very much teaching the spirit of Java where code is delegated to classes and leaves the main application as a few short method calls, making it readable in its own right, and allowing code that uses the same data type to be shared between programs. ...
|Test driven development, and class design, from first principles (using C++)
I'm teaching OO / class design from first principles today ... in stages. The chosen source language is C++, but the principles are well applied across other OO languages too.
Stage 1 - write your test program to make sure it works for your customers want to do. Remember that the "customer is king" ...
|When should I use OO techniques?
We have two friends. They're married. She's a keen advocate of Object Oriented Programming and he can't stand the approach. So take them to the pub, buy them a couple of drinks each, mention OO programming and watch the feathers fly ;-)
Seriously, Object Oriented Programming has its place - and there ...
|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 - ...
|Teaching OO - how to avoid lots of window switching early on
One of the major benefits of Object Oriented programming is the clear and sharp dividing lines it provides between the different sections of logic - where code dealing with one type of data is specified, written, stored and tested in different files to the code dealing with other types of data (or code ...
|Storing your intermediate data - what format should you you choose?
Many applications require data to be held at intermediate stages - stored. What format should be used? ... HUGE subject.
1. If there is already an industry standard / draft standard way of doing it, think very carefully before going for anything else. The standard will have been designed with ease ...
|Inheritance, Composition and Associated objects - when to use which - Python example
• Inheritance is where one object is based on another.
• Composition is where one object contains another.
Question: Which should I use?
Answer: Probably BOTH!
On yesterday's Python course, the question came up, and I wrote an illustrative answer - source code [here]. The scenario we ...
| From Structured to Object Oriented Programming.
A frequent comment - "I'm very used to conventional / structured programming, but I'm now trying to learn about Object Orientation and I don't understand the idea and I get baffled by all the buzzwords I hear". And a request "Can you help me?"
Yes - I can help you. If you come on a course ...
|Rooms ready for guests - each time, every time, thanks to good system design
It's no accident that your room's ready for you when you check in at Well House Manor, and that the bathroom is sparkling.
And it's no accident that the bed has been remade during the day while you're attending your course or you're out at work or seeing the sights.
Our online systems keep a record ...
|When you should use Object Orientation even in a short program - Python example
I was training earlier this week in a room with a view - a view of a major link road towards Cambridge City centre, and I was struck by the very different mix of vehicles travelling along the road compared to what I would expect to see in Wiltshire. And - ever keen to have new, relevant data sets available ...
|Spike solutions and refactoring - a Python example
Refactoring - taking a program that works (as far as it goes) and restructuring it so that it can go much further - that its code can be reusable, that it's more robust, that it can be updated to do more, and so on.
Spike Solution - an answer to a problem that can go no further, and perhaps ignores ...
|Why you should use objects even for short data manipulation programs in Ruby
It's so easy to take the "Bull at a gate" approach - to start writing code to do the job in hand without giving thought to code-reuse later on, or indeed to how the work can be used again later. And it's double easy to, for me to take the bull approach during a course, where I'm writing a short demonstration ...
|Designing your application - using UML techniques
When you're planning to write an application, you shouldn't just start writing code - you should think about what you're going to do and plan ahead. But how do you plan ahead? How do you ensure that you've thought of things from various angles?
UML (Unified Modeling Language) is a way of drawing (modeling) ...
|Your PHP website - how to factor and refactor to reduce growing pains
As your project grows ... what do you change? In an ideal world, you would know exactly what you were coding before you started, and write the full job to spec to last for many years. This isn't an ideal world, though. Our web site has changed over the years - we now have "version 8" (See [here] to ...
|Ruby - a training example that puts many language elements together to demonstrate the whole
Towards the end of our programming language training courses, we pull together all the various strands into a worked example that shows how they go together. I've just posted such an example from last week's Ruby Programming Course ... [here].
Let's have a look at some of the things in the example ...
|Object Oriented Programming for Structured Programmers - conversion training
I've been programming for many years; I started off with languages like Fortran and quickly learned that it's a good idea to split the code into named chunks - which were known as FUNCTIONs and SUBROUTINEs. This means that parts of a program can be tested named chunk by named chunk, that chunks can ...
|Comments in and on Perl - a case for extreme OO programming
"The only thing that will interpret Perl is a Perl interpreter" ... how those words rang in my ears this morning as I was writing some code to highlight source code comments in a different colour in our web site examples. The words were spoken by Larry Wall ... I think it was 10 years ago, so I may ...
|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 ...
|Turning an exercise into the real thing with extreme programming
Should a private course that's being booked run for 2 days or 3? Or on a longer subject for 5 days or 4? I'm often left having to make a recommendation. Budget constraints, and more critically the constraints on the length of time that people can be released from their other tasks, favor a shorter ...
|Program for reliability and efficiency - do not duplicate, but rather share and re-use
When you're writing a new piece of code - especially if you're also quite new to programming - you'll be concentrating so much on getting it to work that you may not be giving too much thought to making it easy look after your code later on (maintainance), nor to sharing a piece of code between programs. ...
|Should Python classes each be in their own file?
Should classes each be defined in a file of their own? In Java, unless you're making a use of inner classes, you're coerced into writing one class per file. In C++, you'll typically have the code for a class in one source file and the headers in another, as other schemes are impractical to use and ...
|Relationships between Java classes - inheritance, packaging and others
When you're designing classes in Java, you need to consider their relationship with one another in various ways.
• You need to consider class INHERITANCE - which classes are based on which other classes. For example, a Pet could be based on (i.e. extended from) an Animal.
• You need to consider ...
|The Light bulb moment when people see how Object Orientation works in real use
A big "light bulb" moment for many customers is when they "get" object inheritance. And one of the best ways of explaining it is by writing an example.
On Wednesday, I wrote an example during our Python Course - taking a customer of Well House Consultants as my base class, then defining two extended ...
|Containment, Associative Objects, Inheritance, packages and modules
Containment is where one object contains other objects - and it happens all over the place. A "town" object may, in a program, contain a number of "hotel" objects, a "location" object, zero or more "leisure" objects, "public transport hub" objects and so on.
Containment is different to inheritance ...
|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 ...
|The Multiple Inheritance Conundrum, interfaces and mixins
Should an OO programming language support "multiple inheritance"? Let's define multiple inheritance first - starting from simple (single?) inheritance.
I don't want to have to define each type of thing ("class of object") from scratch, so I'll define once class as being based ...
|Plan your application before you start
Planning your project / application ahead of time can save you so much heartache and wasted time that it's untrue - but there is still a tendency for people to jump right into to coding without thinking "how will this work". And you should think "How will this work" in many ways.
These seven diagram ...
So said one of my delegates on todays course - pronounced with a long "I" - "Seemples". And we knew he was impersonating one of those meerkats here. One of the classics of modern advertising along with the Cadbury's Gorilla.
Object Oriented Programming is one of those subjects that many people find ...
|Object Oriented programming - a practical design example
Object Oriented coding makes enormous sense when you're looking at a medium sized or larger application - but it's a complete change of thought process for the traditional structured programmer.
We ran an Object Oriented Programming in PHP course today, and the course concluded with me taking some sample ...
When I travelled from home to Saudi Arabia in May, 2006, I planned ahead. Flights were booked, course manuals printed, Visa obtained, contacts established, deposit paid (to us for courses), travel insurance in place before I even left home. "Of Course" or "Prudent", I expect you'll say. And I agree ...
|Designing a heirarcy of classes - getting inheritance right
You friend Will has written a class to handle management information about articles. It's great as far as it goes, but you want to add extra stuff to it, so you persuade Will to give you a copy. He's a nice guy, he does so ... but then a month later he tells you he's added a lot more code and you're ...
|Teaching Object Oriented Java with Students and Ice Cream
"I'm getting tired of students. Can we do something else". So said my delegates at Cardiff University today. So we did Ice Cream and other deserts!
Perhaps I had better explain. I'm running a Java Course there, and looking for examples of classes and objects to write about. At the start of the course, ...
|Object Oriented Tcl
Object Oriented Tcl ([incr-Tcl]) is darned good - but it's only a requirement in a small proportion of the Tcl Training Courses that I give. So it was with real pleasure that I spent some time yesterday writing an example in front of my class in the Nottingham area to show them just how fabulous it ...
|Object Oriented Programming in Perl - Course
Perl Review (module P251) Subroutines in Perl (module P209) More than Simple Lists and Hashes! (module P217) Object Orientation: Individual Objects (module Q906) Creating your own Classes (module P213) Object Orientation: Composite Objects (module Q909) More Objects (module P218) Object Orientation: ...
|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.
|What are factory and singleton classes?
Do you find some of the OO terminolgy baffling? Once you've learnt about constructors and methods, inheritance, overloading and polymorphism and statics, you might think you're there. Then someone mentions a "factory class" or a "singleton" ...
Fear not - factory and singleton classes are posh names ...
|Maintainable code - some positive advice
Don't ask what class an object belongs to
Don't enquire where your cursor is
Don't do two things in a call
Don't duplicate data or code
Don't put two or more values in the same cell
There's lots of different ways of coding - from "dog's dinner" to "Picasso". The dog's dinner looks a mess and is very ...
|Build on what you already have with OO
If I start recalling a "Goons" sketch, then I'll show my age .... but never mind. It was a RERUN that I saw ;-)
Spike Milligan is counting votes at an election. "Two thousand, six hundred and forty two". "Two thousand, six hundred and forty three". "Two thousand, six hundred and forty four" ...
|Comparison of Object Oriented Philosophy - Python, Java, C++, Perl
There are two different philosophies that have been adopted by the authors of Object Oriented languages.
The first approach is to set the thing up in such a way that a programmer who uses someone else's code as the basis for his isn't going to be trusted to use that other person's code in a sensible ...
|The Fag Packet Design Methodology
Old fashioned engineering - in the Midlands of England. Imagine the scene as some widget or other was designed at the turn on the last century. Chimneys belching smoke out over the "Black Country", and workers belching smoke out from their Players, Marlboro or Senior Service.
I've oft heard the term ...
|OO - real benefits
I was reminded of the real power of OO based systems and good object design yesterday. Taking a whole series of already-written classes, I was able to bolt together a new application based on the same data in just a few lines of code and get it running on a website too. The real saving comes not in ...
OO Design - some basics.
Start with a good understanding of OO.
And also a good understanding of the buzz words and design cycle..
Micro or Macro?.
Specifying classes and methods.
Specifying extended classes.
Clusters of classes.
Generalise it out.
Programming and method standards.
Unified Modelling Language (UML).
Project management and design issues.
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.