html5-img
1 / 170

Object Oriented Programming in APL

Object Oriented Programming in APL. A New Sense of Direction (Oh, Oh!) Dan Baronet 2006 V1.01. Introduction. Interoperability & 64 bit OS New WS management New primitives & enhancements to others Object Orientation. V11 has been released. Here are the major features:.

nerita
Download Presentation

Object Oriented Programming in APL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Object Oriented Programming in APL A New Sense of Direction (Oh, Oh!) Dan Baronet 2006 V1.01

  2. Introduction • Interoperability & 64 bit OS • New WS management • New primitives & enhancements to others • Object Orientation V11 has been released. Here are the major features: OOAPL

  3. This talk is based on 2 things: • Why? Why should I know about this? Why am I here? • OK, I’m still here, how do I use it? OOAPL

  4. Synopsis Why should I be here? • Reasons How do I use this? • History of OO • Definitions • The APL way • Implementation details Real Life Example (SJT) OOAPL

  5. Reasons: why do this? • Because Object Orientation is a Valuable Tool of Thought! • To be able to Share Tools and Components more Easily • To help us Manage Complexity in all Project Phases • To use .Net more easily OOAPL

  6. .Net was already in V10 The ability to use .Net with classes was already there in V10 but it was more difficult to use. OOAPL

  7. History OO is not new, it’s been around for a while. Pretty much the same story as APL 50s: conception 60s: 1st implementation (SIMULA compiler) 70s: 1st user base, Smalltalk compiler 80s: into Eiffel to bridge the “gap” 90s: popularity grows (≠APL) thanks to C++ and Java OOAPL

  8. The evolution of data • Elementary data elements (like int) and arrays of them (all the same) • Structures (like {i: int; d: date}), many elementary elements or structures (recurs) • Namespaces (structures whose elements are referred to by name) • Classes (namespaces with initializers & cleaners) OOAPL

  9. Data in Dyalog APL (DYW) In DYW all these objects exist. You can often simulate one by another. For ex: a table of names & values can represent a namespace of variables. DYW can also store the ⎕OR of a namespace. OOAPL

  10. The evolution of data In traditional (procedural) systems, data is separated from code: d a t a code OOAPL

  11. The evolution of data This is the same in traditional APL systems, data is separated from code: OOAPL

  12. private code private code d a t a d a t a The evolution of data In OO systems, data is more tightly coupled with code: Do this Do that OOAPL

  13. private code private code d a t a d a t a The evolution of data In OO APL systems, data is also tightly coupled with code but in a more procedural manner: OOAPL

  14. The Object Oriented paradigm Definitions OOAPL

  15. OO fundamental concepts The Object Oriented paradigm is based on: • Classes • Instances • Members • Message passing • Inheritance • Encapsulation • Polymorphism OOAPL

  16. OO fundamental concepts 1. Classes A class defines the abstract characteristics of a thing, akin to a blueprint. It describes a collection of variables and methods (functions), possibly with a constructor method that can be used to create objects of the class and a destructor to remove the objects thus created. OOAPL

  17. OO fundamental concepts Classes A classcan implement one or more interfaces. An interface describes what it should do. The class describes how it should be done. If a class implements an interface it should do it completely, no partial implementation is allowed. OOAPL

  18. Interfaces - example The following maneuvering interface describes what has to be done with a machine: Method Steer (direction); // where to go Method Accellerate (power); // go faster Method SlowDown (strength); // go slower It does NOT specify how it should be done. OOAPL

  19. Interfaces - example This car object implements maneuvering: Class car : maneuvering; Method SteeringWheel: implements maneuvering.Steer (turn); ... Method GasPedal: implements maneuvering.Accellerate (push); ... Method BreakPedal: implements maneuvering.SlowDown (hit); ... OOAPL

  20. Interfaces - example This plane object implements maneuvering: Class plane : maneuvering; Method Stick: implements maneuvering.Steer (move); ... Method Handle: implements maneuvering.Accellerate (pushpull); ... Method Flaps: implements maneuvering.SlowDown (degree); ... OOAPL

  21. OO fundamental concepts 2. Instances Those are tangible objects created from a specific class. Upon creation any specific action is carried out by the constructor of the class if need be. Upon destruction, the destructor is responsible for cleaning up. OOAPL

  22. OO fundamental concepts 3. Members This is the code and the data of a class. The code is divided into Methods (functions) and data is divided into Fields (variables). There are also Properties which are Fields implemented via functions to read/set them. All these are visible from outside when Public or invisible from outside if Private. OOAPL

  23. OO fundamental concepts Members: Methods Those can either reside in the class (shared method) or in the instance (instance method). There are also abstract methods (e.g. in interfaces) with no code, only calling syntax. Constructors and destructors are methods. OOAPL

  24. OO fundamental concepts Members: Fields Those can either reside in the class (shared field) or in the instance (instance field). They can also be read only. OOAPL

  25. OO fundamental concepts Members: Properties Those are Fieldsimplemented by accessing methods, i.e. PropX←value is implemented by SET value They can either reside in the class (shared property) or in the instance (instance property). OOAPL

  26. OO fundamental concepts 4. Message passing This is the (usually asynchronous) sending (often by copy) of a data item to a communication endpoint (process, thread, socket, etc.). In procedural languages it corresponds to a call made to a routine. OOAPL

  27. OO fundamental concepts 5. Inheritance This is a way to avoid rewriting code by writing general classes and classes that derive from them and inherit their members. This helps achieve reusability, a cornerstone of OO. OOAPL

  28. OO fundamental concepts Inheritance We say that a (derived) class is based on another one. All classes (but one) are derived from another one or by System.Object (the default) OOAPL

  29. OO fundamental concepts Inheritance: Based classes (reusability) A class can be based on another based class. See classCollie based on Dog based on Animal Big Dane: Dog Instances Dog: Animal Fido (Collie) Animal Classes Collie: Dog Fish: Animal Rex (Collie) OOAPL

  30. OO fundamental concepts Inheritance When an instance is created from a class based on another one it inherits all its members automatically. Members can be redefined but subroutines must be specifically set to override base class subroutines. OOAPL

  31. OO fundamental concepts Inheritance: multiple inheritance A class can be based on several other classes. See class Mule made out of 2 different classes. Horse Mule Donkey OOAPL

  32. Override concept Class B Class A M1 M2 M1 M2 M2 ‘I am B’ M2 ‘I am A’ // M1 calls its own M2: (NEW B).M1 I am B // M1 calls its own M2: (NEW A).M1 I am A OOAPL

  33. Based classes Class B: A Class A There is no M1 in B so A’s (on which B is based) M1 is used M1 M2 M2 ‘I am A’ M2 ‘I am B’ // M1 calls its own M2: (NEW B).M1 I am A // M1 calls its own M2: (NEW A).M1 I am A OOAPL

  34. Based classes Class B: A Class A There is no M1 in B so A’s (on which B is based) M1 is used M1 M2 M2: Override ‘I am B’ M2 ‘I am A’ // M1 calls its own M2: (NEW B).M1 I am A // M1 calls its own M2: (NEW A).M1 I am A A:M2 does not allow to be overriden OOAPL

  35. Based classes Class B: A Class A There is no M1 in B so A’s (on which B is based) M1 is used M1 M2: Overridable M2: Override ‘I am B’ M2 ‘I am A’ // M1 calls its own M2: (NEW B).M1 I am B // M1 calls its own M2: (NEW A).M1 I am A A:M2 does allow to be overriden AND B wants to override it OOAPL

  36. OO fundamental concepts 6. Encapsulation • Hides the underlying functionality. • It conceals the exact details of how a particular class works from objects (external or internal) that use its code. • This allows to modify the internal implementation of a class without requiring changes to its services (i.e. methods). OOAPL

  37. Example: a car Consider a car: the functionality is hidden, it is encapsulated, you don’t see all the wiring inside, you’re only given specific controls to manipulate the car. OOAPL

  38. Encapsulation To allow access to a member there are various level definitions. For example, to expose a member you must use some syntax that will declare it public. By default, private is the norm. OOAPL

  39. OO fundamental concepts Encapsulation: private A private member cannot be seen from anywhere. Only other Methods can access it from inside the class if private shared or from within the instance if private instance. M is only seen in the pale area sub1 sub2 OOAPL

  40. OO fundamental concepts Encapsulation: protected A protected member can only be seen from within the instance of from within instances within it. M is only seen in the pale area sub1 sub2 OOAPL

  41. OO fundamental concepts Encapsulation: public A public member can be seen from anywhere. All Methods can access it from anywhere whether it is public shared or public instance. M is seen in all the pale area sub1 sub2 OOAPL

  42. OO fundamental concepts Encapsulation: friend A class declared friend can see the offerer’s private and public members. Class B Class A Private Av Public Au Private Pv Public Pu Friend A Here A sees B’s members as its own members OOAPL

  43. OO fundamental concepts 7. Polymorphism It is behavior that allows a single definition to be used with different types of data. This is a way to call various sections of code using the same name. Typed languages can tell the difference by looking at the “signature” of the functions (their number of arguments and their types) OOAPL

  44. OO fundamental concepts Polymorphism example Foo (integer arg) { // fn called with // an integer arg Print “Int arg” } Foo (string arg) { // fn called with // a string arg Print “String arg” } Same function name, different code OOAPL

  45. OO fundamental concepts Polymorphism A program that accepts multiple definitions is said to be overloaded. Sometimes arguments have to be coerced into a new type to achieve proper behaviour. OOAPL

  46. OO Concepts Summary • OO is based on +-7 key concepts • Classes are blueprints • Instances are objects created from classes • They contain members (data & code) • Their access is restricted • The relation between classes is based on inheritance or specific access OOAPL

  47. End of OO basics QUESTIONS ? OOAPL

  48. The Dyalog APL way OOAPL

  49. Implementation • Dyalog follows C# rules closely • The extensions to the language have been made in following with the :Keywords scheme introduced in the 90s (All new keywords start with ‘:’ ) • Some new system functions have been added and • Some new system commands also OOAPL

  50. Implementation Let’s see how Dyalog APL does this: • Classes • Instances • Members • Message passing • Inheritance • Encapsulation • Polymorphism OOAPL

More Related