470 likes | 604 Views
OpenGOOP Inheritance Project. As presented by Jim Kring November 4th, 2003. What is OpenGOOP?. OpenGOOP is OpenG's version of GOOP that's 100% pure G and Open Source Provides Data encapsulation and multiple instances by reference. Visit http://OpenG.org/opengoop/ for more info.
E N D
OpenGOOP Inheritance Project As presented by Jim Kring November 4th, 2003
What is OpenGOOP? • OpenGOOP is OpenG's version of GOOP that's 100% pure G and Open Source • Provides Data encapsulation and multiple instances by reference. • Visit http://OpenG.org/opengoop/ for more info. OpenG Group Meeting
Who’s working on it • Niels Harre • Jean-Pierre Drolet • Jim Kring • others… OpenG Group Meeting
Presentation Outline • What is inheritance? • Why is inheritance important? • How can we do OpenGOOP Inheritance OpenG Group Meeting
What is inheritance? • Inheritance Nomenclature • VI Server Analogy (What LabVIEW User’s already know about Inheritance) • Inheritance of Attributes and Methods • Class Type • Polymorphism • Encapsulation OpenG Group Meeting
Inheritance Nomenclature • Inheritance defines the relationship “is a” (as compared with “has a”). • It allows a class to inherit the attributes and methods of another class. OpenG Group Meeting
OpenGOOP Inheritance Nomenclature • OpenG has adopted a “familial” inheritance terminology. • Parent, Child • Ancestor, Descendant • There many other nomenclatures used by many other programming languages... OpenG Group Meeting
Other Inheritance Nomenclatures • parent class • superclass (smalltalk) • base class (C++) • child class • subclass (smalltalk) • derived class (C++) OpenG Group Meeting
Inheritance and VI Server • LabVIEW users are already familiar (to some degree) with Inheritance, from experience with VI Server Object References. • All LV objects inherit from “Generic” • Front Panel “Controls” inherit from GObject which inherits from “Generic” OpenG Group Meeting
VI Server Obj Inheritance (cont'd) • Not only do descendants inherit from ancenstors but they also “extend” them. • Control “extends” Gobject • Gobject “extends” Generic OpenG Group Meeting
Inheritance of Attributes & Methods • A child class inherits the publicly accessible properties and methods of its parent. • A child class can add its own properties and methods. This “extends” the parent class. OpenG Group Meeting
Class Type • Each class has a type. • Each object has a type. • The type of an object may be more specific than the type of the wire that it is flowing through. • We can make wires more specific, or more general by type coercion/casting… OpenG Group Meeting
Class Type Coercion No Coercion of GObject (least common) Refnum • Descendants will coerce to an ancestor type. • Once coerced, we can only access properties and methods of the "less specific” class Generic is least common, here OpenG Group Meeting
Upcasting and Downcasting Types • Again, Objects “know” their type, even when contained in a more generic reference type. • We can convert a generic typed wire to a more specific type, using “To More Specific Class”. OpenG Group Meeting
Why not just TypeCast RefNums? • What if the object is not of the more specific class type? Run-Time Error 1057 occurred at To More Specific Class in MakeStrict.vi Possible reason(s): LabVIEW: Type mismatch: Object cannot be typecasted to the specified type. Run-Time Error 1058 occurred at Property Node (arg 1) in MakeStrict.vi Possible reason(s): LabVIEW: Specified property not found. No Error Checking on TypeCast OpenG Group Meeting
RefNums are Analagous to Variants • Variants have Data and Type Descriptor • Refnums have Data and Class ID/Name In both cases: • the type of an object isn't known until run time. • run-time type/error checking is required. OpenG Group Meeting
Polymorphism (Dynamic Dispatch) • A public method may be declared a Virtual Method. • Virtual Methods are placeholders (think call by reference/plug-in) • The Virtual Method dynamically calls the youngest descendant’s method of the same name. OpenG Group Meeting
Polymorphism (Dynamic Dispatch) • A Virtual Method (generic function) can operate on many classes of objects (different types), because the specific class will provide the “real” method (at run-time). • This differs from LabVIEW’s “Polymorphic VIs” which require all types to be known at edit time… OpenG Group Meeting
Static Polymorphism vs Virtual Methods • Static Polymorphism means that the VI must know how to handle all possible types ahead of time. • Virtual Method Polymorphism means that the class of the object received by a VI at run-time provides the implimentation and the VM dynamically invokes the class's VI. (think plug-in) OpenG Group Meeting
Encapsulation • Classes Can have private and protected data • Private data is not visible (readable) outside the class, not even by descendants. • Protected data is visible (readable) by descendants, but descendants cannot write to an ancestors protected data. OpenG Group Meeting
Why is Inheritance Important? • Advanced Software Reuse • Class Inheritance • Forward Compatibility through Polymorphism • Software Engineering • Design Patterns • UML • CASE Tools OpenG Group Meeting
Advanced Software Reuse • Inheritance - We can reuse an existing class by inheriting from it and customizing it to suite our more specific needs. Upgrading an ancestor automatically upgrades all descendants. • Polymorphism - We can create generic tools that will operate on classes that don’t yet exist! This is forward compatibility. OpenG Group Meeting
Software Engineering • Inheritance will open up new worlds in LabVIEW Software development. Computer Scientist and Software Engineers have been doing OOP for a long while so the roadmaps already exist. • Design Patterns • UML • CASE Tools OpenG Group Meeting
Design Patterns* Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice. -- Christopher Alexander, architect and professor emeritus at Berkeley * But, most of these patterns require inheritance and polymorphism (virtual methods) in order to implement. OpenG Group Meeting
Design Patterns • Creational Patterns • Abstract Factory • Builder • Factory Method • Monostate • Prototype • Singleton • Behavioral Patterns • Balking • Chain Of Responsibility • Command • Hierarchical Visitor • Interpreter • Lock • Mediator • Memento • Observer • Scheduled Task • State • Strategy • Template Method • Visitor • Structural Patterns • Adapter • Bridge • Composite • Decorator • Designs • Facade • Flyweight • Iterator • Proxy • Retrofit Interface OpenG Group Meeting
Unified Modeling Language (UML) The Unified Modeling Language (UML) is the industry-standard language for specifying, visualizing, constructing, and documenting the artifacts of software systems. It simplifies the complex process of software design, making a "blueprint" for construction. OpenG Group Meeting
UML – at a glance • Class Diagram and so many others… OpenG Group Meeting
CASE Tools Computer Aided Software Engineering Tools provide environments for developing models and often times integrate with a development environment to automate code generation. OpenG Group Meeting
LabCASE? • With LabVIEW Scripting on the horizon, maybe we will someday have CASE tools that integrate with LabVIEW. • Today, use of class/pattern templates may be a stop-gap solution OpenG Group Meeting
OpenGOOP Inheritance OpenGOOP Inheritance Roadmap: • Define requirements and features • Options and their feasibility • Analyze options and define specification • Development and release Actually, there’s a lot happening in parallel! OpenG Group Meeting
Requirements and Features • Single inheritance • Encapsulation - Protected and Private Object Attributes • Dynamic Dispatch to Virtual Methods • Descendants can override Virtual Methods of ancestors • Descendents can extend Virtual Methods and VM implementations of ancestors • Data access interface should abstract storage implementation • Must be able to implement Certain OOP Design Patterns (GHJV) OpenG Group Meeting
Options • Refnum • Object Data Store • Virtual Method • Encapsulation OpenG Group Meeting
Refnum • One Option – use the same Refnum type for all classes in a hierarchy? • OpenGOOP Inheritance will use the Class Type Inheritance Refnum which exhibits coercion properties similar to VI Server RefNums… OpenG Group Meeting
Class Type Inheritance RefNum • Uses Variant Coercion within clusters… OpenG Group Meeting
CTIR - Coercion • Uses Variant Coercion within clusters… Upcasting Works, but downcasting doesn’t OpenG Group Meeting
CTIR – Sister Classes • Note that sister classes don’t coerce, and they shouldn’t. OpenG Group Meeting
CTIR - Coercion Example OpenG Group Meeting
Object Data Store • Same a OpenGOOP – Reentrant LV2 Global Called By Reference (RLV2GCBR) • Each Class stores its own data. • Inherited data is obtained from the parent class, which obtained from its parent, etc. • CTIR is used to store individual class references. OpenG Group Meeting
Virtual Methods • The Virtual Method looks for a descendant implementation OpenG Group Meeting
Method Registration • At object construction time, each class populates a method table, caches it, and passes it to its parent. The parent populates it, caches it, and passes it to its parent, and so on. OpenG Group Meeting
Method Implementation Look-up • Look up method from Virtual Methods Cluster OpenG Group Meeting
Extending Methods • A method can call an ancestor’s implementation, to avoid rewriting code. OpenG Group Meeting
Encapsulation • Inheritance Data • Public, Protected, Private OpenG Group Meeting
OpenGOOP Inheritance Example • Drawing Geometric Figures… OpenG Group Meeting
A Wizard • … OpenG Group Meeting
Recap… • We need inheritance! • Then we can do SW Engineering! • OpenG is trying to find the most natural framework for G. • Join in… OpenG Toolkit Developers List OpenG.org >> Navigate >> Developers >> Mailing List OpenG Group Meeting