Training, Open Source computer languages

PerlPHPPythonMySQLhttpd / TomcatTclRubyJavaC and C++LinuxCSS

Search our site for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
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 for something you would naturally write anyway, applied to certain techniques so that they can be described in OO design texts, project specifications, and articles such as this.

A SINGLETON is a class for which only one object member ever exists; you can create a class that's a singleton by writing the constructor so that it returns a truely fresh object the first time you call it, and a reference to the same object should you call it again. We have an example (in Python, but it applies to any language in principle) here

A FACTORY is a class who's constructor returns an object which might be in one of several different classes, not necessarily including the class in which it is, in theory, the contsructor. I could, for example, have a base class called "accom" for accommodation, subclassed to "hotel" and "campsite". If calls to the "accom" constructor return a hotel or a campsite (depending on constructor parameters), then that accom class is a factory. We have an example of a factory (in PHP, but it applies to any language in principle) here. There's also an exanple in Perl ... the class containing the factory method is available here, sample code that calls it here and the other class that may be built here
(written 2007-06-04 17:59:27)

 
Associated topics are indexed under
Q907 - Object Orientation and General technical topics - Object Orientation: Design Techniques
H108 - Objects in PHP
Y112 - Python - Objects - Intermediate
P218 - Perl - More Objects
C233 - C and C based languages - OO in C++ - beyond the basics
R108 - Ruby - More Classes and Objects
J710 - Java - Extending Classes and More

Back to
Five of the best - pictures from London
Previous and next
or
Horse's mouth home
Forward to
Sunday afternoon

Some other Articles
Bathtubs and pecking birds
for loop - how it works (Perl, PHP, Java, C, etc)
Judging the quality of contributed Perl code
Sunday afternoon
What are factory and singleton classes?
Five of the best - pictures from London
An update on Perl - where is it going?
New Serieses for the summer on TV
MySQL - the order of clauses and the order of actions
What brought YOU to our web site?
1638 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 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).

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