Private and Public - and things between
A public train service is one which is available for anyone to travel on; a private one only takes limited passengers as invites / made available by the operator. And there could be intermediate levels too - I understand that at times the British Transport Police protect the last train from Weymouth to Bristol on a Saturday night from the more inebriated members of the public who wish to travel on it. Then you have package trips available - such as [this one]
next September, which is open to the public, but only if they join a group.
It gets more interesting when you consider that a public train service can be provided by a private company, and that even within the public accessible railway premises, there are areas which are protected from access from the public and are only available to staff who, however, may not be staff actually employed by the private company that runs the stations and trains.
Why all the rules about who can do what? It would be downright dangerous to allow members of the public, without appropriate health and safety training, do wander around at will even on a publicly owned railway. And if such training was given, and precedents were set, the new system would provide yet another set of rules and regulations that had to be looked after and updated as each new station opened( ;-) ) and each new train type came into service. So the best thing is to allow a single way of doing each operation that's needed by the public user, and then to provide protected or private methods of delivering those requirements.
The first picture illustrate a train at Shiplake, operated by the First group which is private / protected (a plc) but operating a public service from Henly-on-Thames (population 12,000) to Twyford (for London) through village at least once an hour. The second picture illustrates a private railway in a garden in Shiplake. The only trains there are provided and run by the owner for his own use, and it would be an exceptional day indeed if he were to run services for the general public.
Where am I headed?
I'm drawing a real life parallel to computer programming, where various elements of a program are often marked "public" or "private", and where there are often levels in between - the most commonly used intermediate word is "protected" and sometimes the word "package" is used too, although each of these words has slightly different meanings depending on the programming language that we're talking about.
Starting with a standard that applies across all languages. If something is described as "public" then it's available to any programmer who wants to use it. And if something is described as "private" then it's available only within the tight area of the programming unit - usually a class - in which it is defined. The public can make use of private elements indirectly, however, by calling up a piece of code marked 'public' within a class which within itself makes a call to a private element.
The beauties of using private members like this are two-fold. Firstly, the private method can be changed later on without the need for the public user to make any changes to allow for it (this is known as encapsulation), and secondly there's only a limited number of facilities that need to be ruggedised and safety audited for use by the public, as private ones have a firm lock on the door!
, the additional level of "protected" says that a member is available within its own class (so as it would be if it were private), AND within other classes which are derived - either directly or indirectly - from that class. Yesterday, I wrote a new example - a [source code] which included a base class called animal. I extended the animal into a specialized subclass called silentanimal, and then I defined four types more finely - dogs (which bark from time to time, and it depends on the dog how much it barks), sealions (all of which bark 20 times a day), giraffes (which don't bark), and cats (which don't bark either, but which are going to have their names displayed a bit differently). PHP does *not* have an extra package level.
Both C++ and Java also use private, protected and public - and also have a "package" level which is unstated and again comes somewhere in the middle. There's a full set of notes and diagrams that we've provided for Java [here - .pdf file]. And you'll notice that "protected" in Java does not relate to the class inheritance structure, but to Java's packages and subpackages.
In languages such as Perl, it's assumed that the programmer knows what (s)he's doing, and there aren't any of the "private" and "public" words. Which makes for much quicker coding if the assumption is correct, and a nightmare or maintainance if it isn't ...
Public Well House Consultants courses which include Object Orientation:
Perl for Larger Projects
Object Oriented PHP
Learning to program in Python
Learning to program in Ruby
Learning to program in Java
Learning to program in C++
C and C++ programming
Object Oriented techniques, and how they're implemented in each of the languages above, are also covered if required on private (single company) courses which can be run for you at our training centre, or at your offices.
[incr-Tcl] is an Object Oriented extension to Tcl, and we can cover it on private Tcl courses; if you're on either of our public Tcl courses and would like the subject added in, please let the tutor know and he'll be happy to add an extra hour or two before or after lessons on the final day of the course (no extra charge!).
Lua is not strictly an object oriented language, but its metatables provide something that's very close and with the same philosophy; we cover them on our public Lua courses, and they'll usually be covered on private courses too (subject to tailoring - very occasionally they won't be required)
(written 2011-01-22, updated 2011-01-25)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articlesC233 - C and C based languages - OO in C++ - beyond the basics
 Object factories in C++, Python, PHP and Perl - (2014-12-19)
 Extended and Associated objects - what is the difference - C++ example - (2013-01-18)
 Associated Classes - using objects of one class within another - (2012-07-21)
 Destructor methods in C++ - a primer - (2011-11-05)
 C++ - objects that are based on other objects, saving coding and adding robustness - (2011-04-17)
 C and C++ - preprocess, compile, load, run - what each step is for - (2011-04-12)
 C++ - putting the language elements together into a program - (2011-01-08)
 C++ objects - some short, single file demonstrations - (2011-01-07)
 C++ - a complete example with polymorphism, and how to split it into project files - (2010-11-16)
 Objects and Inheritance in C++ - an easy start - (2010-07-01)
 Complete teaching example - C++, inheritance, polymorphism - (2010-01-15)
 Calling base class constructors - (2008-10-03)
 What a lot of files! (C++ / Polymorphism demo) - (2008-06-12)
 C - structs and unions, C++ classes and polymorphism - (2008-03-13)
 What are factory and singleton classes? - (2007-06-04)
 C++ - just beyond the basics. More you can do - (2006-11-14)
 Comparison of Object Oriented Philosophy - Python, Java, C++, Perl - (2006-08-13)
 Simple polymorphism example - C++ - (2006-07-14)
 References and Pointers in C++ - (2006-07-10)
H108 - Objects in PHP
 Learning about Object Orientation in PHP - a new set of examples - (2013-04-28)
 stdClass in PHP - using an object rather than an associative array - (2013-04-02)
 Objects in PHP - Revision - (2012-12-16)
 Caching Design Patterns - (2012-08-20)
 Copying, duplicating, cloning an object in PHP - (2012-08-18)
 Autoload in PHP - (2012-08-17)
 How do classes relate to each other? Associated Classes - (2012-02-12)
 Design Patterns - what are they? Why use them? - (2012-02-12)
 Designing your application - using UML techniques - (2012-02-11)
 Computer Graphics in PHP - World (incoming data) to Pixel (screen) conversion - (2011-03-24)
 Catchable fatal error in PHP ... How to catch, and alternative solutions such as JSON - (2011-03-22)
 Getting the OO design write - with PHP a example - (2010-08-14)
 Does copying a variable duplicate the contents? - (2010-08-14)
 PHP - Object Oriented Design in use - (2010-05-21)
 What is a factory? - (2010-04-26)
 The Multiple Inheritance Conundrum, interfaces and mixins - (2010-04-11)
 Static class members in PHP - a documented example - (2010-03-16)
 Object Oriented Programming in PHP - (2010-02-19)
 Shipping a test harness with your class in PHP - (2010-02-12)
 Serialization - storing and reloading objects - (2009-10-04)
 Abstract classes, Interfaces, PHP and Java - (2009-10-03)
 Object Oriented programming - a practical design example - (2009-08-27)
 PHP4 v PHP5 - Object Model Difference - (2009-05-11)
 Cleaning up redundant objects - (2009-05-11)
 When should I use OO techniques? - (2009-05-11)
 PHP - getclass v instanceof - (2009-05-07)
 Introduction to Object Oriented Programming - (2008-12-06)
 Sorting objects in PHP - (2008-10-04)
 Accounts in PHP - an OO demo - (2008-06-19)
 OO PHP demonstration - comparing objects and more - (2008-02-08)
 Object Oriented Model - a summary of changes from PHP4 to PHP5 - (2007-04-18)
 Cue the music, I'm happy. - (2007-01-09)
 Build on what you already have with OO - (2006-08-17)
 Planning a hotel refurb - an example of a Gant chart in PHP - (2006-05-14)
 Think about your design even if you don't use full UML - (2006-03-24)
 North, Norther and Northest - PHP 5 Objects - (2005-11-04)
 Don't repeat code - use loops or functions - (2005-08-21)
 Should I use structured or object oriented? - (2005-06-10)
 PHP5 lets you say no - (2005-02-07)
 PHP v Java - (2004-11-20)
 Object Oriented Programming in PHP - (2004-09-29)
J709 - Java - Class Access
 What is a universal superclass? Java / Perl / Python / Other OO languages - (2010-11-13)
 When should I use Java, Perl, PHP, or Python? - (2009-12-13)
 Where is my Java class? - (2009-09-24)
 Who can use which access door? - (2006-09-21)
Q909 - Object Orientation and General technical topics - Object Orientation: Composite Objects
 Jargon busting - (2011-01-30)
 Relationships between Java classes - inheritance, packaging and others - (2010-07-10)
 Designing a heirarcy of classes - getting inheritance right - (2009-05-11)
 Screw it or Glue it? Access to Object variables - a warning - (2007-09-12)
 Perl and Shell coding standards / costs of an IT project - (2007-09-11)
 NOT Gone phishing - (2006-02-05)
 Class, static and unbound variables - (2005-10-25)
R108 - Ruby - More Classes and Objects
 Standard methods available on all objects in Ruby - (2012-06-23)
 Private, Protected, Public in Ruby. What about interfaces and abstract classes in Ruby? - (2012-06-23)
 Why you should use objects even for short data manipulation programs in Ruby - (2012-06-10)
 Ruby - a training example that puts many language elements together to demonstrate the whole - (2011-04-23)
 Ruby training - some fresh examples for string handling applications - (2011-02-05)
 Changing a class later on - Ruby - (2011-02-02)
 Ruby - examples of regular expressions, inheritance and polymorphism - (2010-10-02)
 What is a factory method and why use one? - Example in Ruby - (2010-09-30)
 Object Oriented Ruby - new examples - (2010-02-03)
 Direct access to object variable (attributes) in Ruby - (2010-02-02)
 Defining a static method - Java, Python and Ruby - (2010-02-01)
 Tips for writing a test program (Ruby / Python / Java) - (2010-01-29)
 Ruby objects - a primer - (2010-01-29)
 Ruby - is_a? v instance_of? - what is the difference? - (2010-01-27)
 Object Orientation in Ruby - intermediate examples - (2009-07-16)
 Some Ruby programming examples from our course - (2008-03-21)
 MTBF of coffee machines - (2005-01-20)
T245 - Tcl/Tk - [incr-Tcl]
 Object Oriented Tcl - (2008-02-02)
 Object Orientation in Tcl - [incr-Tcl] - (2005-04-24)
U107 - Object Orientation - the Lua way
 Dot or Colon separator between table name and member in Lua - what is the difference? - (2014-05-06)
 Metatables, Metamethods, classes and objects in Lua - (2014-03-18)
 Is Lua an Object Oriented language? - (2013-06-15)
 What is a metatable? How do I set one up? How do I use them? Lua - (2012-05-12)
 Using Lua tables as objects - (2012-05-11)
 Special __ methods you can use in Lua metatables - (2012-04-12)
 Weak references in Lua - what are they, and why use them? - (2012-04-04)
 Metaclasses (Python) and Metatables (Lua) - (2011-11-17)
 Tables as Objects in Lua - a gentle introduction to data driven programming - (2011-08-17)
 __index and __newindex in Lua - metatable methods - (2010-04-05)
 Lua Metatables - (2010-04-02)
 Is Lua an Object Oriented language? - (2010-04-01)
 Lua examples - coroutines, error handling, objects, etc - (2009-10-15)
 A fresh example - objects the Lua way - (2009-08-13)
 For Lua Programmers AND for Town Planners - (2009-08-02)
 First class functions in Lua lead to powerful OO facilities - (2008-08-07)
 If you are learning Lua, here are some more examples - (2008-07-06)
 Towards Object Oriented Programming in Lua - (2008-06-30)
Some other Articles
Strings in C
Structures v Structure Pointers in C. How, which, why.
Setting up arrays in C - fixed size at compile time, or dynamic
Private and Public - and things between
Wiltshire Rail services - a golden opportunity
Django - separating the HTML from the view / model
Steering our Python courses towards wxPython, SQLite and Django
Django - adding your own views, and then templating your views.
Training Classes - should the training company provide a system for each delegate to use?
4350 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 at 50 posts per page
This is a page archived from The Horse's Mouth at
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).