Board Logo
« object-oriented programming »

Welcome Guest. Please Login or Register.
Nov 21st, 2009, 9:25pm



Conforums Terms of Service | Membership Rules | Home | Help | Search | Recent Posts | Notification | Format Your Message | Vista/Win7 FAQ


Pages: 1 2  Notify Send Topic Print
 hotthread  Author  Topic: object-oriented programming  (Read 414 times)
lionpie
New Member
Image

member is offline

Avatar




PM


Posts: 2
xx object-oriented programming
« Thread started on: Oct 26th, 2009, 10:11am »


What i understand is that Object-oriented programming helps against having many subprograms called libraries. As other
people change it and so many versions with the same name exist. Kopies of a library as virtual copies, other people can use but not change. But a few pages later in the book 'programming for dummies' there is something mentioned as
'polymorfism'

The books writes that this technique you can overwrite the subprogram without changing the original code.
thus you have the same name but you replaced the instructions.

My question is:
I don't see any difference using OOP and not.
Because in both situations you have the same subprogram (library) but the 2nd one has different coding.....
Am i missing somethinghuh

Pls explain in very plain Engish...i am just a starter. Many thanks
User IP Logged

tsh73
Senior Member
ImageImageImageImageImage

member is offline

Avatar




PM

Gender: Male
Posts: 931
xx Re: object-oriented programming
« Reply #1 on: Oct 26th, 2009, 11:05am »

OOP supposes using objects
Objects are data structures (user defined types, grouping different things togeter) - thing that JB lacks
- coupled with functions to work on that data (methods)

Bottom line: this concept is not applicable to Just Basic. Do not bother. (or choose some OO language, not JB)
« Last Edit: Oct 26th, 2009, 11:06am by tsh73 » User IP Logged

Q: "And if I took your codes and compile them, and sell them for a profit"?
A: Go ahead. I had my share of good then I coded it for fun, if you can make better use of it - please do.
lionpie
New Member
Image

member is offline

Avatar




PM


Posts: 2
xx Re: object-oriented programming
« Reply #2 on: Oct 26th, 2009, 11:15am »


Thanks... will forget it for now.
I just hate it when writers write about something and let it 'float' in the air without telling exact what it means, how to do it, etc etc... lipsrsealed
User IP Logged

tooanalytical
Senior Member
ImageImageImageImageImage

member is offline

Avatar




PM


Posts: 1088
xx Re: object-oriented programming
« Reply #3 on: Oct 26th, 2009, 1:00pm »

on Oct 26th, 2009, 11:15am, lionpie wrote:
Thanks... will forget it for now.
I just hate it when writers write about something and let it 'float' in the air without telling exact what it means, how to do it, etc etc... lipsrsealed

I have the same strong opinion. If anyone knows ways to apapt programming in JB to concepts of this "Object Oriented" way to arrange information, please explain the idea and show examples. NONE of the reading that I have done help me in understanding O.O.P. How do you make the transition from numeric variable, string variable, arrays; to objects, classes, methods?
User IP Logged

Stefan Pendl
Administrator
ImageImageImageImageImage

member is offline

Avatar

Let's talk JB ...


PM

Gender: Male
Posts: 2158
xx Re: object-oriented programming
« Reply #4 on: Oct 26th, 2009, 2:07pm »

The JB GUI commands for controls or the graphics commands are more or less methods of the GUI object, which is represented by its handle.

#m.txt "!font courier_new 12"

This calls the font method of the static text control object #m.txt, which will set the font to the one specified.

OOP is not easy to explain, it is much easier to get the grips of it, by using an OOP language.
User IP Logged

Stefan

Any code I post can be used by others in their own projects, there is no need to ask for permission, just give credit if you like

Just BASIC 1.01, Windows Vista Home Premium SP2, AMD Turion X2 RM-70 2GHz, 4GB RAM
jaba
Junior Member
ImageImageImage

member is offline

Avatar




PM

Gender: Male
Posts: 96
xx Re: object-oriented programming
« Reply #5 on: Oct 26th, 2009, 2:31pm »

on Oct 26th, 2009, 2:07pm, Stefan Pendl wrote:
The JB GUI commands for controls or the graphics commands are more or less methods of the GUI object, which is represented by its handle.

#m.txt "!font courier_new 12"

This calls the font method of the static text control object #m.txt, which will set the font to the one specified.

OOP is not easy to explain, it is much easier to get the grips of it, by using an OOP language.

I believe I read in Carl Gundel's blog, that he is adopting a more object oriented approach towards using controls in his upcomming LB versions. Something like using a "font" method in this example instead of writing to the control. Maybe #m.txt(font=Arial) or something like this.

I don't pretend to understand all this; I'm just trying to recall what I read.
User IP Logged

Stefan Pendl
Administrator
ImageImageImageImageImage

member is offline

Avatar

Let's talk JB ...


PM

Gender: Male
Posts: 2158
xx Re: object-oriented programming
« Reply #6 on: Oct 26th, 2009, 6:17pm »

Download the free Run BASIC version and you will be able to play with the new syntax.
User IP Logged

Stefan

Any code I post can be used by others in their own projects, there is no need to ask for permission, just give credit if you like

Just BASIC 1.01, Windows Vista Home Premium SP2, AMD Turion X2 RM-70 2GHz, 4GB RAM
alix
WikiAdmin

member is offline

Avatar

To arrive at the simple is difficult


Homepage PM


Posts: 217
xx Re: object-oriented programming
« Reply #7 on: Oct 27th, 2009, 4:25pm »

Quote:
I have the same strong opinion. If anyone knows ways to apapt programming in JB to concepts of this "Object Oriented" way to arrange information, please explain the idea and show examples.


see : http://justbasic.wikispaces.com/AlixCorner
User IP Logged

Beginner ? Want to create your own games?
Coolprog is for you !
http://www.coolprog.com
uncleBen
Senior Member
ImageImageImageImageImage

member is offline

Avatar




PM


Posts: 1496
xx Re: object-oriented programming
« Reply #8 on: Oct 27th, 2009, 6:20pm »

alix: OOP has very little to do with the ability to break code up into several files. This just requires a mechanism to import and/or link different files but doesn't tell anything about programming style (e.g perfectly procedural code in C can be broken up into multiple source files).

I suppose the starting point for OOP is the ability to have user-defined objects and define functions that work with them.

Even in C one can define structs and functions that work with structs. It's not just the syntax how a method call looks like, that defines coding style. There is very little conceptual difference whether the call to Bark method looks like:

Code:
Lassie.Bark()
 


or

Code:
Bark(Lassie)
 


(And a language like Python would be perfectly happy with either syntax. Using the dot syntax is just syntactic sugar.)

To some extent creating and using objects and methods appears to be possible with modules in RunBasic. For example one can write a "point" module like the following, with an init() method to set the values, toString$() method to get the string representation of a point, and most notable a moveBy() method to change the values of one point by the amount specified by another (vector addition).

Code:
global x, y
wait

function init(a, b)
    x = a
    y = b
end function

function getX()
    getX = x
end function

function getY()
    getY = y
end function

function moveBy(#hOther)
    x = x + #hOther getX()
    y = y + #hOther getY()
end function

function toString$()
    toString$ = "(" + str$(x) + ", " + str$(y) + ")"
end function
 


Now one can write a program that uses the modules as objects:

Code:
run "point", #location
run "point", #increment

#location init(10, 20)
#increment init(5, 6)

print "Initially"
print #location toString$()
print #increment toString$()

#location moveBy(#increment)

print "After moving"
print #location toString$()
end
 


I suppose modules were mostly intended as a mechanism to break up large projects into reusable pieces, but they can be used to code in a somewhat OOPish style.

Naturally there are many other things one would want from objects, such as inheritance (a Dog object is a kind of Animal and can be used wherever an Animal is wanted) or even the ability to store objects in arrays.
« Last Edit: Oct 27th, 2009, 6:20pm by uncleBen » User IP Logged

Passing arrays to subroutines, functions that work with any types, quick string indexing and much more - JBExtensions.

Tired of Minesweeper? Try TomatoSweeper
jaba
Junior Member
ImageImageImage

member is offline

Avatar




PM

Gender: Male
Posts: 96
xx Re: object-oriented programming
« Reply #9 on: Oct 28th, 2009, 03:54am »

I thought it would be fun to try to represent a simple JB program in the manner of an object oriented language. You can begin to see some of the issues uncleBen spoke of.

A simple program asks for your name and prints hello to you.

Code:
nomainwin

WindowWidth=500
WindowHeight=400
statictext #main.inst, "Enter your name here", 20, 20, 200, 20
textbox #main.getName,                    20, 50, 200, 25
textbox #main.message,                    20, 100, 200, 25
button #main.ok, "OK", [buttonClicked],  UL, 250, 50, 20, 20
open "Hello, username" for window as #main
#main, "trapclose [quit]"
#main.getName, "!setfocus"
wait
[buttonClicked]
#main.getName, "!contents? name$";
#main.message, "Hello, "+name$
wait

[quit]
close #main
end

 


The same program expressed in OO syntax - somewhat! But it works. And it was fun!
I know this is NOT OOP. Just an exercise in defining the program as if everything were an object.

Code:
global name$, message$ '(instead of parameters)

[StartMainProgram]
    nomainwin
    call Window.createWindow
    call Window.getInput
    call Window.Text.Combine
    call Window.printTo

[EndMainProgram]
    wait
    call Window.close handle$
    end


'No attempt is made to assign arguments that would be passed to subs or routines

sub Window.createWindow
    [Window.class.window]
        [window.alias]
        class$="window"
        [window.title]
        title$="Hello, userName"
        [window.size]
        wide=500
        high=400
        WindowWidth=wide
        WindowHeight=high
    [control.Text]
        [Text.static]
        statictext #main.instruct, "Enter your name here", 20, 20, 200, 20
        [Text.input]
        textbox #main.getName,                             20, 50, 200, 25
        textbox #main.message,                             20, 100, 200, 25
    [control.button]
        button #main.ok, "OK", [buttonOkClicked],       UL, 240, 50, 20, 20

    [Window.open]
    open title$ for window as #main
        [open.terminate]
        #main, "trapclose Window.close"
end sub

sub Window.getInput
    [control.focus]
    #main.getName, "!setfocus"
    wait
    [buttonOkClicked]
    [Text.readInput]
        #main.getName, "!contents? name$";
end sub

sub Window.Text.Combine
    message1$="Hello, "
    message$=message1$+name$
end sub

sub Window.printTo
    [control.Text]
        [Text.output]
        #main.message, message$
end sub

sub Window.close handle$
    close #handle$
end sub
    end

 


hehehe...
I guess the reason it works is because all the branch labels that would name classes, methods, properties and proceedures are just ignored here. And where they are extents on the Window object, they are just labels - not a reference to - or call to - a method in some other part of the program.
« Last Edit: Oct 28th, 2009, 10:11am by jaba » User IP Logged

zlatkoJB
Junior Member
ImageImageImage

member is offline

Avatar

author of Aurel Basic


Homepage PM

Gender: Male
Posts: 94
xx Re: object-oriented programming
« Reply #10 on: Oct 28th, 2009, 09:06am »

Quote:
In an OOP language, your program is made out of several files, so you will have myprogram.bas, MyClass1.bas, MyClass2.bas, Myclass3.bas


This is not OOP then spliting program in modules which
dont have nothing with OOP.
This examples are very funy but definatly is not OOP.
OOP is little bit tricky to explain someone which is
used to standard procedural programming.
I understand something but all concept not even
I dont lik them to much.
User IP Logged

author of Aurel Basic
alix
WikiAdmin

member is offline

Avatar

To arrive at the simple is difficult


Homepage PM


Posts: 217
xx Re: object-oriented programming
« Reply #11 on: Oct 28th, 2009, 10:06am »

All I was trying to say is that you need more than one file to do OOP .... . It was not meant as a definition. rolleyes

My approach was : how is OOP programming different form JB programming? and that's the first difference I could think of.
User IP Logged

Beginner ? Want to create your own games?
Coolprog is for you !
http://www.coolprog.com
uncleBen
Senior Member
ImageImageImageImageImage

member is offline

Avatar




PM


Posts: 1496
xx Re: object-oriented programming
« Reply #12 on: Oct 28th, 2009, 11:10am »

You don't need more than one file. You can have the code all in the same file, no matter how OOP it is.

If you want to get an idea how OOP might be different see the following:

Code:
animals$(1) = Dog$("Lassie")
animals$(2) = Cat$("Fluffy")
for i = 1 to 2
    call Animal.Speak animals$(i)
next i
end

function GetType$(o$)
    GetType$ = word$(o$, 1, chr$(0))
end function

function Animal.Name$(a$)
    Animal.Name$ = word$(a$, 2, chr$(0))
end function

function Dog$(name$)
    Dog$ = "dog" + chr$(0) + name$
end function

sub Dog.Speak dog$
    print Animal.Name$(dog$); " barks"
end sub

function Cat$(name$)
    Cat$ = "cat" + chr$(0) + name$
end function

sub Cat.Speak cat$
    print Animal.Name$(cat$); " purrs"
end sub

sub Animal.Speak animal$
    select case GetType$(animal$)
        case "dog": call Dog.Speak animal$
        case "cat": call Cat.Speak animal$
    end select
end sub
 


Now imagine this supported directly by language features, and you don't need to implement the dynamic dispatch manually (select case in Animal.Speak) nor encode the object data as a string.

For example in Python:

Code:
class Animal():
    def __init__(self, name): self.name = name
    def speak(self): raise NotImplementedError("speak method not implemented")

class Dog(Animal):
    def __init__(self, name): Animal.__init__(self, name)
    def speak(self): print self.name, "barks"

class Cat(Animal):
    def __init__(self, name): Animal.__init__(self, name)
    def speak(self): print self.name, "purrs"

if __name__ == "__main__":
    animals = [Dog("Lassie"), Cat("Fluffy")]
    for animal in animals:
        animal.speak()
 
« Last Edit: Oct 28th, 2009, 12:57pm by uncleBen » User IP Logged

Passing arrays to subroutines, functions that work with any types, quick string indexing and much more - JBExtensions.

Tired of Minesweeper? Try TomatoSweeper
JohnDavidson
Administrator
ImageImageImageImageImage

member is offline

Avatar




Homepage PM


Posts: 3745
xx Re: object-oriented programming
« Reply #13 on: Oct 28th, 2009, 12:47pm »

To my way of thinking, Subs and Functions are the closet things to Objects we can program in JB.
If you routinely use certain Subs and Functions in you applications they may be stored as modules.
These modules may be pasted into your program or, with a little code, be appended in at build time.

Larger programs can be written in modules and they will definitely be easier to maintain.
How you deal with these modules is up to you.
You may create separate TKNs from each module or compile the modules into one BAS file to create the application's TKN.
Separate TKNs can be treated as external objects if your code allows any object to call any other object as needed.

Passing information between external objects (TKNs) in JB is kind of clunky but doable.

John

User IP Logged

John Davidson
e-me: johnshomeport@yahoo.com
My JB Page: http://john.jbusers.com/
Did ya Libby yet? http://lblibby.com/
uncleBen
Senior Member
ImageImageImageImageImage

member is offline

Avatar




PM


Posts: 1496
xx Re: object-oriented programming
« Reply #14 on: Oct 28th, 2009, 1:00pm »

But Subs and Functions alone just make structured procedural programming.

If you don't use anything to structure the code, you get something like a Big Ball of Mud
« Last Edit: Oct 28th, 2009, 1:01pm by uncleBen » User IP Logged

Passing arrays to subroutines, functions that work with any types, quick string indexing and much more - JBExtensions.

Tired of Minesweeper? Try TomatoSweeper
Pages: 1 2  Notify Send Topic Print
« Previous Topic | Next Topic »

Conforums Terms of Service | Membership Rules | Home | Help | Search | Recent Posts | Notification | Format Your Message | Vista/Win7 FAQ


New Monthly Ad-Free Plan!

$6.99 Gets 50,000 Ad-Free Pageviews!
| Free Shoutboxes | Hookah |

This Board Hosted For FREE By Conforums ©
Get Your Own Free Message Board!