Hi guys, firs of all, im sorry for my bad english..
How can i learn OOP, its really hard and detailed. Firs of all, i dont know why i must use OOP.
Welcome to DaniWeb bsod1,
OOP(Object Oriented Programming) is the order of the day! It is very useful as in it is very flexible as it allows many methods present in a class to be accessed via an object of that class, and so, there are innumerable things that you can do with a really good OOP language(such as Python).
OOP isn't that hard, once you learn the concepts, such as classes, methods and objects and the basics, things really start to get interesting.
Considering the fact that you have created this thread in the Python section, I am guessing that you want to start learning Python. Well, www.python.org is the best place to start. If you have doubts be sure to come here and post them, and we are here to help you! ;)
In Python most everything is an objects, so you are using OOP from the start.
If you talking about the use of classes, then basically you have another tool to organize larger programs.
You can collect functions that belong together under the class header. These function are commonly called methods of a class. This way you can create several different instances of the class, each containing the same methods. That is where the power comes in, since you don't have to rewrite the class every time. Python keeps track of which instance you are using. Here is an example:
# a look at a simple Python class class Animal(object): # uses newer class style, inheriting very basic class 'object' def __init__(self, animal, sound): # __init__() is the 'constructor' of the class instance # when you create an instance of Animal you have to supply # it with the name and the sound of the animal # 'self' refers to the instance # if the instance is dog, then # name and sound will be that of the dog # 'self' also makes name and sound available # to all the methods within the class self.name = animal self.sound = sound def speak(self): # a method's arguments always start with self print( "The %s goes %s" % (self.name, self.sound) ) # create a few class instances # remember to supply the name and the sound for each animal dog = Animal("dog", "woof") cat = Animal("cat", "meeouw") cow = Animal("cow", "mooh") # now you can call each animals function/method speak() # by simply connecting instance_name and speak() with a '.' cow.speak() cat.speak() dog.speak() # you can also access variables associated with the instance # since cow is the instance # self.sound becomes cow.sound print(cow.sound) # --> mooh
You can go further and let one class inherit another class. You can see that in larger programs this will help keep things organized and readable. For smaller programs you don't need to write a class, but is good practice.
thank you guys, its really great starting for me.
Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.
Private Sub btn_addline_Click(ByVal ...
Hi, as I was told that my code doesn’t scale well at all, I thought perhaps I’d try to get a better understanding of interfaces/abstract classes and classes and the relationship between them.
I don’t want at this stage work on a big separate project as I've already got plenty ...
OK, so HostGator for some reason no longer allows gcc/g++ access unless you have a Designated Server account, which is a lot of money to spend just to compile my "Hello World" program. Thus I figured I'd compile at home, then upload. Program is your regular old bare-bones Hello World ...