Jump to content

Evaluate My OOP Layer Design


Recommended Posts

I was about to make a particular program in AutoIt and as I was designing it, I came to find that it was so suited to object orientation that I came to think about how I might emulate those practices through AutoIt. Remembering how it's been said a million times that OOP is "never" going to be in AutoIt, I realized I would have to take my own approach which would work with AutoIt. So I designed a library which makes AutoIt have pseudo-object-orientation. Before you anti-OOP people realize, I'll just say, yes pseudo object oriented programming's acronym is POOP, but that doesn't change quality of my work. :)

It will all be written as a (*.au3) library. It includes lots of key OOP stuff including variable and method access privileges (public and private for now), single parent inheritance and object orientation (instantiation of unique objects based off of classes with unique properties and capabilities).

So, I have a pretty full idea and written design for the backend and am about to get into the development of that. But that's not what I am interested in talking about here. What I am here to discuss is the front end. Below is sample front end code, i.e. what a scripter/programmer using the Psuedo Object Orientation Library (POOL) would have to write. It creates an object, idles, and then exits. Nothing important, but it demonstrates some OOP concepts (I was too lazy to show inheritance). So could you guys give me some feedback on the good and bad about using a command set as shown below?

Here is a commentless version:

CreateClass("frame")
                  AddMethod("close", "public")
                  AddMethod("OnButtonclick")
                  AddVar("title")
                  AddVar("width")
                  AddVar("height")
                  AddVar("top")
                  AddVar("left")
                  SetParent("")
                      Func frame() 
                          set("top", "-1")
                          set("left", "-1")
      
                          dim $unit = 100
                          set("this width", 4*$unit)
                          set("height", 3*$unit)
                          
                          set("title", get("width")&"x"&get("height")&" window")
                          
                          GUICreate(get("title"), get("width"), get("height"), get("left"), get("top"))
                          GUISetState(@sw_show)
                      EndFunc
      
                      Func frameclose()
                          GUIDelete()
                      EndFunc
      
                      Func frameOnButtonclick()
                          
                      EndFunc
      
              $frame_object = addObject("frame")
              Sleep(1000)
              obj("close()", $frame_object)

And a commented version

//Create a class
              CreateClass("frame")

                  //Give it methods, unspecified priviledge means private, defaults to last created class
                  AddMethod("close", "public")
                  AddMethod("OnButtonclick")

                  //Give it some variables.  Defaults private variable in most recently created class.  Can be array.
                  AddVar("title")
                  AddVar("width")
                  AddVar("height")
                  AddVar("top")
                  AddVar("left")

                  //Set no parent.  By default there is no parent...just figured I should show this method
                  SetParent("")

                  //Methods for the class
                      Func frame() 
                      //    A method of the same name as the class always defines the constructor.  If 
                      //    the user does not define the method, POOL will simply set all instance variables to 0.  If the 
                      //    user does define the method the user's version will be called instead.

                          set("top", "-1")//Set's the object variables
                          set("left", "-1")
                          
                      //    This is traditional AutoIt still, regular variables inside methods are local and behave as they should, OOP or not
                          dim $unit = 100

                          set("this width", 4*$unit)//since in frame, 'this' is implied object specification is optional.  Acceptable representations are "this width", "this_width" and "this.width"
                          set("height", 3*$unit)//As stated, defaults object to "this" if unspecified
                          
                          //reads width (400) and height (300) to set the title to "400x300 window" 
                          set("title", (get("width") & "x" & get("height") & " window"))
                          
                          GUICreate(get("title"), get("width"), get("height"), get("left"), get("top"))
                          GUISetState(@sw_show)
                      EndFunc
      
                      Func frameclose()
                          //The method naming requires that the method starts with the class's name.
                          //Function frameclose() is called as:
                          //        obj("[frameObject] close()"), obj("[OBJECT] [METHOD]()")
                          //    OR
                          //        obj("close()", [frameobject]), obj("[METHOD]()", "[object]")
                          GUIDelete()
                      EndFunc
      
                      Func frameOnButtonclick()
                          
                      EndFunc
              //Done with class
      
              //Instantiate and do stuff...this program does nothing useful, just shows the OOP commands

             //Make the OBJ
              $frame_object = addObject("frame")

             //Chill
              Sleep(1000)

             //Call close() in object
              obj("close()", $frame_object)
Edited by Creative

"Everything is vague to a degree you do not realize till you have tried to make it precise." - Bertrand Russell [The Philosophy of Logical Atomism]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...