As an answer to the "un-escapable loop" problem I had a few days back, Object Oriented concepts are directly relevant. The virtual space an object take can be a complex topic and I will try to explain as I can.
Objects are just representation of a concept, or a class in VB. When creating a new object, you use the keyword "New" to tell the compiler that this object is totally another thing. When you have a clsChair class, you ideally want to pump out a chair that is going to be distinguished by other with its properties, its name, tag or any other. When VB sees the "New" keyword, its meaning to create another area in memory where this chair will be stored at. If you have two "New"' 's you will have two areas in your memory allocated to chairs.
Similarly, you can omit the "New" keyword entirely. And it will not give you an error. Because if you do not specify the "New", you will just use the class as default and only object. And note here, ONLY object. Meaning he will re-use the default one over and over.
I say defaut but its not exactly that way, an object is pointed to by its reference address. Say our class resides inside the memory at 0x11AA00, thats the "reference" I will be using. Lets say I want to get the number of legs our chair has, I tell my computer to look at whatever class is stored at 0x11AA0 and return me whatever leg property is in there. It will NOT use the name of the class you defined. And this is exactly the problem.
When using the technique I used, that is, not using a new. You end up with every object ( in this case, pictureboxes) using the same address. Same address means properties having the same values. When looping through my image matrix, the lowerbound and upperbound had the same reference address, therefore the first object is ALSO the last one. Which explains why it stopped after a single iteration. Because it already complete ALL its run in a SINGLE shot ( because every other tile were already affected instantly ).
Take a look at this picture:
This is a blog to talk about programming. I am a student in IT currently working with the C# language.
Showing posts with label OOP. Show all posts
Showing posts with label OOP. Show all posts
Saturday, March 27, 2010
Thursday, February 25, 2010
Classes Overview
Today we had to use classes. I will try to explain briefly what classes are, without going into too many details, because this is a deep subject.
First off classes are concepts of "things". A thing can be pretty much anything you can interact with. Chairs, tables, cars and clothes are all classes. Objects are physical representation of those concepts ( or logical, in the case of computers ). The particular chair you are standing on is the physical representation of the "chair" concept. Chairs are things which have several legs and a plate on which you can sit. But the one you are sitting on right now may have a number of legs and style and paint, it is unique ( even more unique when you think about the atoms making your chair ). Class = Chairs and Object = [The one chair you're sitting on].
Creating a class is made that way:
Public Class Car 'The class definition
Dim typeOfCar as string 'This is called a Member, it is specifically a property of a class (i.e a variable )
Sub nameCar(byval newValue as string) 'This is another member, it is a procedure.
typfOfCar = newValue
End Sub
Sub nameCar(byval newValue as string) 'This is another member, it is a procedure.
typfOfCar = newValue
End Sub
End Class
By inserting the following snipper we have now created a Class called Car, it is a very general and broad class right now. It has a single property called typeOfCar that defines what type of car we're talking about. Right now it has no value so it can be anything. It a concept. When we create it, we define the car. We give it a brand, a name, a maximum speed, number of doors and etc. This is called an instance of a car. And creating an instance of a class is as easy as creating any other variable.
Dim MyViper as New Car
MyViper.nameCar("My Big Car")
We now have a living representation of a "car", its a dodge viper and its name is "My Big Car". We have given it a name using our member by accesing it using the syntax Class_Name.Procedure_Name
As you see, an instance of a class is an object. And the class itself that defines the procedures and properties is a Class. By using Object Oriented Programming you can do many things functional programming cannot do. The code you make is a lot neater and well structured. OOP is a lot more complex than that but thats all I'm going to risk explaining else if make some error and give you bad knowledge. That is all for today, hope to see you next time !
By inserting the following snipper we have now created a Class called Car, it is a very general and broad class right now. It has a single property called typeOfCar that defines what type of car we're talking about. Right now it has no value so it can be anything. It a concept. When we create it, we define the car. We give it a brand, a name, a maximum speed, number of doors and etc. This is called an instance of a car. And creating an instance of a class is as easy as creating any other variable.
Dim MyViper as New Car
MyViper.nameCar("My Big Car")
We now have a living representation of a "car", its a dodge viper and its name is "My Big Car". We have given it a name using our member by accesing it using the syntax Class_Name.Procedure_Name
As you see, an instance of a class is an object. And the class itself that defines the procedures and properties is a Class. By using Object Oriented Programming you can do many things functional programming cannot do. The code you make is a lot neater and well structured. OOP is a lot more complex than that but thats all I'm going to risk explaining else if make some error and give you bad knowledge. That is all for today, hope to see you next time !
Labels:
class,
objects,
OOP,
Programming,
School,
Vb.net,
visual basic
Subscribe to:
Posts (Atom)
