oop - Singleton pattern example : The pilot of an aircraft -


is pilot in aircraft or plane , example of singleton pattern ?

this example demonstrates common problem of singletons.

if absolutely sure program have only one plane , only one pilot, yes, can consider pilot singleton.

however, 1 day might need more 1 plane in program, or more 1 pilot in plane. if seems improbable you, never know.

therefore better not rely on global variables, singleton pattern kind of wrapper, explicitly tie plane , pilot. simplest example, might have pilot member in plane object (or maybe pilot& etc.)

however, depends on nature pf program. air fight simulator, when sensible assume each plane has 1 fixed pilot? or airline simulator/manager, when have many planes, many pilots, , @ different time different pilots can fly same plane?

in latter case, suggest no explicit tie between pilot , plane, intermediate object, say, flight, have pilot& , plane& members.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -