object oriented programming in apl n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Object Oriented Programming in APL PowerPoint Presentation
Download Presentation
Object Oriented Programming in APL

Loading in 2 Seconds...

play fullscreen
1 / 165

Object Oriented Programming in APL - PowerPoint PPT Presentation


  • 116 Views
  • Uploaded on

Object Oriented Programming in APL. A New Direction Dan Baronet 2009 V1.22. Dyalog V11 was released in 2006. One of the major features was:. Object Orientation. This presentation is based on two things:. What is Object Orientation programming? How do I use it in APL?. Another tool.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
    Presentation Transcript
    1. Object Oriented Programming in APL A New Direction Dan Baronet 2009 V1.22

    2. Dyalog V11 was released in 2006. One of the major features was: Object Orientation OOAPL

    3. This presentation is based on two things: • What is Object Orientation programming? • How do I use it in APL? OOAPL

    4. Another tool Object Orientation is another tool for programmers. Users won’t see any difference. It is a way for programmers to simplify their lives by supplying each other with already made objects (almost) ready to use. OOAPL

    5. Concepts of the OO paradigm The namespace From the beginning APL had this kind of notion in the form of the workspace Namespace = Workspace? OOAPL

    6. Concepts of the OO paradigm The workspace • It contains everything needed to run an application OOAPL

    7. Concepts of the OO paradigm The workspace • It contains everything needed to run an application • It can be initialized (via []LX) OOAPL

    8. Concepts of the OO paradigm The workspace • It can be initialized (via []LX) • It can be viewed as an object OOAPL

    9. Concepts of the OO paradigm The workspace • It can serve as base and be copied into another workspace Current Workspace In memory FilesUtils FilesUtils )COPY FilesUtils OOAPL

    10. Concepts of the OO paradigm The workspace • It contains everything needed to run an application • It can be initialized (via []LX) • It can be viewed as an object • It can serve as base and be copied into another workspace • It can be modified OOAPL

    11. Concepts of the OO paradigm The workspace problems • Name clashing (using )COPY) Fn1 Fn3 Var1 varx Fn2 varx Fn2 varx )COPY FilesUtils OOAPL

    12. Concepts of the OO paradigm The workspace problems • Name clashing (using )COPY) • They cannot be stored as a unit on file • Only 1 workspace item per component (variable or function) • Need to cleanup when finished OOAPL

    13. Concepts of the OO paradigm The workspace (solutions) The package or overlay • They group items (vars & fns) together • They act as a (static) unit • They can be stored on file • They can be copied, like wss, into existing code and dispersed in it OOAPL

    14. Concepts of the OO paradigm The workspace – packages They were only a partial solution to a more general problem • Name clashing still happened • Clean up was still needed OOAPL

    15. Concepts of the OO paradigm The workspace – namespace In the 80s a company came up with the concept of namespace, probably from other languages like C++ and Java Namespaces are like workspaces but nested. OOAPL

    16. Concepts of the OO paradigm DOS V1.0 APL V1.0 File1,ext var1 File2.ext fn1 Abc.dws var2 Note.txt function_2 Etc.doc etc flat structure OOAPL

    17. Concepts of the OO paradigm DOS V2.0 APL V8.0 Dir1 ns1 File2.ext var1 Abc.dws var2 Note.txt function_2 Folder2 namespace2 Etc.doc fna subf subns file1 fna filex opb Fich.log objxv Tree (nested) structure OOAPL

    18. Concepts of the OO paradigm Each namespace is similar to a workspace - It contains functions, variables (including some system variables) - It can contain an entire application - It acts as a unit: it can be put as a single item on file - It is dynamic: it can be moved into to execute code, no need to disperse contents OOAPL

    19. Concepts of the OO paradigm Each namespace is similar to a workspace Like a workspace, if you need to tweak one you take a copy and modify it: Workspace: Namespace: )LOAD myApp newApp<-[]NS []OR ’myApp’ A<-3 newApp.A<-3 )SAVE newApp OOAPL

    20. Concepts of the OO paradigm Reusability This is one of the key concepts From a template you create a new version possibly modifying it 1 namespace many possibly different versions OOAPL

    21. Concepts of the OO paradigm Reusability Classes are very much like namespaces From a class you create a new version possibly modifying it 1 class many possibly different versions OOAPL

    22. .Net and OO .Net is based on namespaces and supports many OO concepts. Dyalog APL is based on namespaces and supports many OO concepts. They go well hand in hand together. OOAPL

    23. .Net and Dyalog This is not new! The ability to use .Net and create classes was already in V10 but it was more difficult to use. OOAPL

    24. The Object Oriented paradigm Definitions OOAPL

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

    26. OO fundamental concepts 1. Classes A class defines the abstract characteristics of some object, akin to a blueprint. It describes a collection of members (data and code) Classes can be nested OOAPL

    27. OO fundamental concepts Classes ex: House blueprint OOAPL

    28. 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

    29. OO fundamental concepts Interfaces An interface describes how to communicate with an object. Ex: electrical system & electrical outlets OOAPL

    30. 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

    31. 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

    32. Interfaces - example This plane object implements maneuvering: Class plane : maneuvering; Method Yoke: implements maneuvering.Steer (move); ... Method Handle: implements maneuvering.Accellerate (pp); ... Method Flaps: implements maneuvering.SlowDown (degree); OOAPL

    33. 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 (code) of the class if some sort of initialization is required. Upon destruction, the destructor is responsible for cleaning up. OOAPL

    34. OO fundamental concepts 2. Instances New House (Blue): After the creation of the new House the Constructor paints it in blue OOAPL

    35. 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. OOAPL

    36. OO fundamental concepts Members These can reside inside the class if shared or in the instance. Ex: the .Net classDateTime has a member Now that does not require an instance to be called. e.g. DateTime.Now ⍝ straight from the class 2007/10/21 9:12:04 OOAPL

    37. OO fundamental concepts Shared vs Instance Shared members remain in the class S1 S2 S3 I1 I2 I3 I4 Instance members are created in the instance S1 S2 S3 I1 I2 I3 I4 S1 S2 S3 I1 I2 I3 I4 S1 S2 S3 I1 I2 I3 I4 OOAPL

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

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

    40. 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 (sharedproperty) or in the instance (instanceproperty). OOAPL

    41. 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 like Dyalog, it corresponds to a call made to a routine. OOAPL

    42. 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 by avoiding to rewrite code and use what already exists. OOAPL

    43. 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 from System.Object (the default) OOAPL

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

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

    46. OO fundamental concepts Inheritance: simulate multiple inheritance A class can implement several interfaces. Here class Penguin implements 2 different behaviours (interfaces): Fish (swim,eggs) • Penguin: • Swims • Flies not • 1 egg/yr • Croaks Bird (fly,eggs,sing) OOAPL

    47. 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

    48. OO fundamental concepts Inheritance: a derived class inherits all the base members C1 memberA memberB C2: C1 memberC memberD OOAPL

    49. OO fundamental concepts Inheritance: a derived class inherits all the base members C1 memberA memberB memberC C2: C1 memberC memberD OOAPL

    50. OO fundamental concepts Inheritance Initialization is performed by the constructor. If a class is derived, the base class' constructor will also be called if there is one. OOAPL