Announcement

Collapse
No announcement yet.

Discussion why using objects?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Discussion why using objects?

    Maybe you like a discussion when to use objects?

    For people not knowing what to do with a class..

    A class's main feature is being a data container.
    Each newly created instance of a class hold's it's own private data.
    Put the instances in an array and you'll have a collection with unique data per element.
    You can do a similar thing with structures (type variables).

    To 'reach' the data container like a string or long variable inside a class a function aka method or property is required.

    When a class is newly created a signal is given by calling a Create methoid (if implemented by you)
    This way you may set defaults or raise events... whatever.

    When the object is unset a Destroy method can be invoked, this way you can delete memory or close files and so on.

    Basically this is the functionality of a class.
    A black box you let do things, it does not conflict with other instances (like a global variable you ever may have used for some purpose) and runs selfcontained.

    The way PB creates classes is com based and therefore directly usable for other languages (in the form of a dll).

    So the best things are:
    1) Maintains private data per instance.
    2) Can clean up it's mess, guaranteed in any case (unless when an application crashes).
    3) No need to declare functions.. ordinary declarations are daunting!!

    There are much more benefits like multiple references and still being guaranteed of proper clean up but that goes beyond this simple explaination.

    What i am a bit afraid of is that class are going to be used for any silly functionality.
    An ordinary module can be as equally modular as a class.
    Several invokes to functions in a module don't have to interfere with each other.
    Modules can not create unique instances holding private data.
    It's a global variable or a local function variable, nothing else.

    Using classes means, will you hold multiple data blocks?
    By using a class you won't need to mess with memory pointers to 'make' unique data fragments using an old fashion module.

    That a class can have functions is a secundary (but needed) thing.

    Btw, remember a type variable could not have dynamic strings?
    A class can hold dynamic strings and can be seen as a special type variable.

    hellobasic

  • #2
    What i am a bit afraid of is that class are going to be used for any silly functionality.
    Well I'm not afraid at all. This is the encapsulation I have been waiting for.

    Unless you are using a vintage PC ruinng a 16 bit OS I doubt you will see any performance hit or a memory footprint that scares!! Screw it, it's time to use our modern systems and leave legacy stuff for the byte counting purists!!

    Bring it all on. The more encapsulation the better.

    James

    Comment


    • #3
      Real Men don't need no stinkin' "classes" to Encapsulate .

      Besides, I'll be out of the business long before the need for procedural-style ("legacy stuff for the byte counting purists") code has receded.
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        Wow..

        100% for and 100% against haha
        hellobasic

        Comment


        • #5
          I'm not against "OOP" style programming, any more than I am against "DDT" style screen creation.

          Both DDT and "PB Objects" are tools; nothing more, nothing less. They provide programmers with options for creating applications.

          If you prefer programming with "DDT" vs. SDK style, fine. If you prefer using the Object syntax instead of... er, SDK-style programming? - that's fine too.

          But I am sticking to my guns, asserting no tool ever changed a bad programmer into a good one.

          MCM
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            I don't think i am a bad programmer but i would like to have had Classes for a few years now.
            I can work it out with odd memory handles but it's expected that this way of programming only takes more time than a good implementation on a compiler level.

            But like i said, i think a lot of nonsense oop based will pass by soon.
            For myself only a few parts are really worth rewritting to a class.

            I forgot oop style programming here.
            Some like to use this kind of syntax, i don't mind that kind of syntax.
            That is not oop, it's oop syntax.
            hellobasic

            Comment


            • #7
              I would guess a majority(?) of posters in this forum are professional programmers who are not in a position to embrace the new Power Objects in their everyday work. I can understand this but personally I just love to program. To create, experiment, and push the envelope. I jump out of bed every morning at 5am with a "what new things will I discover today" anticipation! I have been known to actually giggle when something new I'm working on actually works the way I want. Did I ever mention I suffer from Peter Pan Syndrom? Poo-Poo the Objects all you want, I am still having more fun than I've had in years.

              James

              Comment


              • #8
                I would guess a majority(?) of posters in this forum are professional programmers who are not in a position to embrace the new Power Objects in their everyday work.
                ... or ...

                I would guess a majority(?) of posters in this forum are professional programmers who already use objects in their everyday work for a long time - just not with PB.


                Procedural and Object Orientated programming are not two opposite poles that don't go together. They interact very well (and very efficently).

                Real Men don't need no stinkin' "classes" to Encapsulate .
                The winning point for me with objects is code readability (which directly translates into code maintenance, which I know you're a big fan of). Consider these two code snippets you might come across into someone's else program:

                Code:
                ' Procedural style
                
                Local lResult As Long
                
                lResult = FileBackup(8088, "http", "www.somehost.com", "www.otherhost.com", "CurrentTransactions.txt", %TRUE)
                You vaguely understand what that line is supposed to do, but for details, you would need to look up the function itself.

                Now, how about this OOP style snippet:
                Code:
                ' OOP style, pseudo code, as I haven't got my copy of PB/WIN 9 yet
                
                Local lResult As Long, Backup As BackupClass
                
                Backup.Port = 8088
                Backup.Protocol = "http"
                Backup.SourceHost = "www.somehost.com"
                Backup.DestinationHost = "www.otherhost.com"
                Backup.File = "CurrentTransactions.txt"
                Backup.OverwriteExistingFile = %TRUE
                lResult = Backup.DoBackup
                Without looking up the procedure's definition and its parameters, the parameters' (properties, in this case) intentions are quite obvious. In the procedural example, is "www.somehost.com" the source or the destination host? And what has the parameter %TRUE for an effect?

                I like this verbose approach. More code to write, but less comments.

                Comment


                • #9
                  Well I am glad PB finally supports OOP (and creating of COM objects). As a third-party developer, it makes it very easy now to create in PB a library for users of other compilers without having to go through the mess of providing header files and procedural-style sample sets for each compiler.

                  All you have to provide is the COM DLL and TLB (plus help files, etc) and that's it. It is truely cross-language. However, that is not to say I would not include a few old-style DLL headers for PB, C and Delphi, but that is all.
                  kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

                  Comment


                  • #10
                    Only an amateur would use string literals like that and expect the code to be understandable

                    Code:
                    Portno          = 8088
                    szProtocol     = "http"
                    szSourceUrl   = "www.somehost.com"
                    szDestUrl      = "www.otherhost.com"
                    szBackupFile  = "CurrentTransactions.txt"
                    bOverwrite    = %TRUE
                    lResult = FileBackup(Portno, _ 
                                szProtocol, _ 
                                szSourceUrl, _
                                szDestUrl, _
                               szBackupFile, _ 
                               bOverwrite)
                    MCM
                    PS: I wouldn't even use string literals where shown. I'd read those values from configuration file/database/registry.
                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      Only an amateur
                      What I liked about Knuth's post was that even an amateur could comprehend the concept.

                      A few posts of that clarity might keep me and others from spinning out on the learning curve.
                      Rod
                      In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

                      Comment


                      • #12
                        Originally posted by Kev Peel View Post
                        Well I am glad PB finally supports OOP (and creating of COM objects). As a third-party developer, it makes it very easy now to create in PB a library for users of other compilers without having to go through the mess of providing header files and procedural-style sample sets for each compiler.

                        All you have to provide is the COM DLL and TLB (plus help files, etc) and that's it. It is truely cross-language. However, that is not to say I would not include a few old-style DLL headers for PB, C and Delphi, but that is all.
                        A major benefit.
                        hellobasic

                        Comment


                        • #13
                          >....that even an amateur could comprehend the concept

                          Well, I am perforce biased but I find the way I rewrote the subject code to be reasonably clear.

                          But if using "object syntax" forces programmers to cut down on inline literals ("magic numbers"), that would be a Good Thing.


                          MCM
                          Michael Mattias
                          Tal Systems (retired)
                          Port Washington WI USA
                          [email protected]
                          http://www.talsystems.com

                          Comment


                          • #14
                            I find the way I rewrote the subject code to be reasonably clear
                            Actually, more than reasonably.
                            A well written, easily understood example of an existing tool, just as Knuth's was of the 'new' tool. And good for comparison, both appreciated by at least one member.
                            Rod
                            In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

                            Comment


                            • #15
                              Originally posted by Michael Mattias View Post
                              Only an amateur would use string literals like that and expect the code to be understandable
                              See, this is why an amateur like me enjoys OOP style. It enforce better coding practice on me.

                              BTW, I very much like this point in Edwin's first post:

                              What i am a bit afraid of is that class are going to be used for any silly functionality.
                              An ordinary module can be as equally modular as a class.
                              I remember when VB introduced classes and everyone and his dog rewrote each and every little one line helper function as a class.

                              Comment


                              • #16
                                As Mr Mattias has said OOP in PB is a tool and we are free to use or not use it. We are also free it use it how we see fit, so one could use:

                                ' OOP style, pseudo code, as I haven't got my copy of PB/WIN 9 yet

                                Local lResult As Long, Backup As BackupClass

                                Backup.Port = 8088
                                Backup.Protocol = "http"
                                Backup.SourceHost = "www.somehost.com"
                                Backup.DestinationHost = "www.otherhost.com"
                                Backup.File = "CurrentTransactions.txt"
                                Backup.OverwriteExistingFile = %TRUE
                                lResult = Backup.DoBackup
                                We could also write the DoBackup routine to accept optional parameters, allowing:

                                Backup.DoBackup Portno, szProtocol, szSourceUrl, szDestUrl, szBackupFile, _
                                bOverwrite)

                                or even have a separate function called DoBackWithParameters (usage and requirements obvious).
                                [SIZE="1"]Reprinted with correections.[/SIZE]

                                Comment


                                • #17
                                  Partial code that will compile using MCM's correct method of getting the parameters from an input file or not.

                                  James

                                  Code:
                                  '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
                                  'SED_PBWIN
                                  '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
                                  CLASS cBackUp
                                  	INSTANCE nPort,OverwriteExistingFile AS LONG
                                  	INSTANCE Protocol,DestinationHost,File,SourceHost AS STRING
                                  
                                  'if this is not to be inherited	use a CLASS METHOD CREATE
                                  	CLASS METHOD CREATE
                                  		nPort = 8088
                                  		Protocol = "http"
                                  		SourceHost = "www.somehost.com"
                                  		File = "CurrentTransactions.txt"
                                  		DestinationHost = "www.otherhost.com"
                                  		OverwriteExistingFile = -1
                                  	END METHOD
                                  	
                                  	INTERFACE iBackUp : INHERIT IUNKNOWN
                                  'If this class will be used as a base class use a Default METHOD
                                  		'METHOD Default()
                                  			'place contnts of CLASS METHOD CREATE Here
                                  		'END METHOD
                                  		METHOD DobackUp
                                  			?"BackUp in progress"
                                  		END METHOD
                                  		PROPERTY SET Port(BYVAL Param AS LONG)
                                  			nPort = Param
                                  		END PROPERTY
                                  		PROPERTY SET Protocol(BYVAL Param AS STRING)
                                  			Protocol = Param
                                  		END PROPERTY
                                  		PROPERTY SET SourceHost(BYVAL Param AS STRING)
                                  			SourceHost = Param
                                  		END PROPERTY
                                  		'add the rest of the properties
                                  	END INTERFACE
                                  	
                                  END CLASS
                                  
                                  FUNCTION PBMAIN()
                                  	LOCAL oBackUp AS iBackUp
                                  	
                                  	oBackUp = CLASS "cBackUp"
                                  	
                                  	IF ISNOTHING(oBackUp) THEN
                                  		? "No oBackUp
                                  		EXIT FUNCTION
                                  	END IF
                                  		
                                  	'Use a ini file for var initialization
                                  	'Input string 
                                  	'If InputStr = "USEDEFAULTS"
                                  		oBackUp.DoBackUp
                                  	'ELSE
                                  	'Parse the string
                                  	'oBackUp.Port = VAL(PARSE$(InputStr,1))
                                  	'oBackUp.Protocol = PARSE$(InputStr,2)
                                  	'........
                                  	
                                  END FUNCTION

                                  Comment


                                  • #18
                                    Code:
                                    'ELSE
                                    	'Parse the string
                                    	'oBackUp.Port = VAL(PARSE$(InputStr,1))
                                                 .......
                                    No, I have not yet tried any of this stuff, but would it not make sense to have the parsing of the command string ("USEDEFAULTS") itself be a method... to keep all properties and methods of the class within the class code?

                                    eg.
                                    Code:
                                        oBackup.SetParameters (COMMAND$)
                                    .. or something like that?
                                    Last edited by Michael Mattias; 24 Aug 2008, 09:34 AM.
                                    Michael Mattias
                                    Tal Systems (retired)
                                    Port Washington WI USA
                                    [email protected]
                                    http://www.talsystems.com

                                    Comment


                                    • #19
                                      Suggestion: Print the help topic to sit-back and enjoy

                                      Before forming negative opinions read the help, completely!
                                      In fact, read it until you get it.
                                      Click Help
                                      Click PB/Win Contents
                                      (Under Keyword Quick finder)
                                      Click Programming Reference
                                      Click COM programming introduction
                                      When you see "What is an object, anyway?
                                      Click Print
                                      Select "Print the selected heading and all subtopics"
                                      17 pages if printed on both sides. Enjoy!

                                      Real men can now use or create OCX's with ease.
                                      Understatement, in-process or out-of process DLL's.
                                      Last edited by Mike Doty; 24 Aug 2008, 10:23 AM.
                                      The world is full of apathy, but who cares?

                                      Comment


                                      • #20
                                        Originally posted by Mike Doty View Post
                                        Real men can now use or create OCX's with ease.
                                        Understatement, in-process or out-of process DLL's.
                                        Afraid not.

                                        James

                                        Comment

                                        Working...
                                        X