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 stations[k]
end
Even if you don't know Ruby, you could probably tell me that my application sets up an Array of Station objects from data in a file called
rstats2014.xyz, sorts those objects into a natural sorting order, and outputs the first 20. And, yes, you would be right!
The detailed internal stuff can be designed, implemeted, tested and debugged by someone who knows all about stations and the data associated with them, and can then be reused by lots of other people who - like the programmer of the code above - perhaps don't know about what's going on inside the class and indeed don't need to know.
For anyone interested ... ... the full application code we wrote is
[here]. It turns out if we look inside that we have a lot of data available to us, and indeed who different classes of stations - those for which we have complete data sets and those which (for various reasons) are incomplete. We define how to sort stations, how to print stations out, how to make a station (or either type) from a raw data line read from our standard data file.
(written 2015-11-21)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
Q908 - Object Orientation and General technical topics - Object Orientation: Design Patterns [485] North, Norther and Northest - PHP 5 Objects - (2005-11-04)
[1224] Object Relation Mapping (ORM) - (2007-06-09)
[2322] Looking for a practical standards course - (2009-08-05)
[2741] What is a factory? - (2010-04-26)
[2977] What is a factory method and why use one? - Example in Ruby - (2010-09-30)
[3608] Design Patterns - what are they? Why use them? - (2012-02-12)
[3716] Learning C++ - a design pattern for your first class - (2012-05-02)
[3810] Reading files, and using factories to create vectors of objects from the data in C++ - (2012-07-21)
[3843] Caching Design Patterns - (2012-08-20)
[4021] Spike solution, refactored and reusable, Python - Example - (2013-02-28)
[4096] Perl design patterns example - (2013-05-20)
[4098] Using object orientation for non-physical objects - (2013-05-22)
[4325] Learning to program - what are algorithms and design patterns? - (2014-11-22)
[4330] Java - factory method, encapsulation, hashmap example - (2014-11-27)
[4356] Object factories in C++, Python, PHP and Perl - (2014-12-19)
[4359] How to avoid too many recalculations within an object - (2014-12-21)
[4377] Designing a base class and subclasses, and their extension, in C++ - (2015-01-01)
[4396] Java Utility class - flexible replacement for array. Also cacheing in objects and multiple catch clauses example. - (2015-01-16)
[4421] How healthy are the stars of stage and screen? - (2015-02-09)
[4626] Singleton design pattern - examples and uses - (2016-01-20)
[4663] Easy data to object mapping (csv and Python) - (2016-03-24)
[4673] Separating detailed data code from the main application - Ruby example - (2016-05-16)
R102 - Hello Ruby Objects [2287] Learning to program in Ruby - examples of the programming basics - (2009-07-15)
[2603] Ruby objects - a primer - (2010-01-29)
[4009] Clear, concise examples - Ruby classes and objects. - (2013-02-17)
[4369] Ruby - the second rung of learning the language - (2014-12-28)
[4580] Easy example - data record to object and object to data record mapping in Ruby - (2015-11-21)
Some other Articles
What is make? What is gcc?Bash ... some new scripts to - handling user inputBack in the saddle again - excellent open source course from Well House ConsultantsA near-empty plate of pastries - sign of a breakfast enjoyedThin application, thick objects - keep you main code simple. Example in RubyBehaviour and test driven development in Ruby using RSpecRail electrification - far, far too optimistic so over budget and late An update - Melksham Link Canal and riverIf it's Tuesday it must be Belgium?