You are not logged in.
I've been writing a library in Python for fancy text output in PyGame programs and like to understand object-oriented programming better as well as develop the best interface for my library. I was wondering if anyone could point me in the right direction. E.g. books or web tutorials, preferably in Python or a similar language.
Personally, I'd rather be back in Hobbiton.
Offline
I would recommend reading Stack Overflow and the Python documentation. They are great resources. However, don't get too caught up in reading, because I have found that I learn a lot through experience.
Offline
More generic but very helpful :
Design Patterns: Elements of Reusable Object-Oriented Software
By Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides
Publisher: Addison-Wesley Professional
ISBN: 0201633612
Offline
It's kind of strange recommending a book on object-oriented programming to an advanced user. Most students (as opposed to self-taught learners) first come across object-orientation in a beginner's text on Java or C++, at least here in BC. Stroustrup's books are pretty great, though they are in C++. Part of the reason why they are great is that S is always explaining why the features that C++ has, in addition to those included in C, are worth learning and using.
---Lenovo T510--Intel(R) Core(TM) i7 CPU M620@2.67GHz---x86_64---4GB RAM---NVIDIA NVS 3100---
---320GB Seagate Momentus 7200.4 Series Hard Drive---
----xfce4---2.6.36-ARCH---
Offline
It's kind of strange recommending a book on object-oriented programming to an advanced user. Most students (as opposed to self-taught learners) first come across object-orientation in a beginner's text on Java or C++, at least here in BC.
And in my opinion, that's a ghastly misjudgment on the part of our CS professors and a hideous flaw in programming education. Head First Design Patterns was pretty good, although it kind of assumes the basics -- but if you already understand inheritance, you're halfway there.
Last edited by Trent (2010-12-07 14:33:34)
Offline
Learning object-oriented languages is always useful (java, ruby). I find ruby to be the most pleasing object-oriented language (literally everything is an object here) and it's in some aspects similar to python.
Python is a strange language, because it "hides" its OO-ness, which makes it (in my opinion) a hard choice to learn object-oriented programming on. Once you know OO, you can learn python
Last edited by JezdziecBezNicka (2010-12-07 17:41:10)
This is my signature. If you want to read it, first you need to agree to the EULA.
Offline
"Python 3 Object Oriented Programming" by one of our own, Dusty Phillips
Awesome, thanks for the recommendation!
I wrote this book specifically for people who know "a little" Python (probably version 2) and want to boost their Python OOP skills and learn Python 3 at the same time. I was basically thinking about sysadmins and similar intermediate users who have been "scripting" python for quite a while, but haven't really done any python "programming." I think it may be exactly what the OP is looking for.
Then again, I also think everyone needs a copy. On a completely unrelated topic, I also believe I should not be banned for spam... /me waves at the mods
Dusty
Offline
Python is a strange language, because it "hides" its OO-ness, which makes it (in my opinion) a hard choice to learn object-oriented programming on.
I'm an object oriented programmer that recently learned Python.
In what ways do you feel Python hides object oriented design principles?
Offline
The language when I first started to learn it seemed procedural. There are some built-in functions like len() that are surprising for oo language (it's len(array), not array.len() for some reason). Also there is no private-protected-public in classes, which introduces some confusion.
This is my signature. If you want to read it, first you need to agree to the EULA.
Offline
I found Smalltalk, Objects, and Design a pretty good OOP book.
Offline
Great thread guys -- can't wait to check out some of these books. I don't know why, but learning languages when I was younger the whole OO thing didn't grasp with me. I recently decided to finally learn things thoroughly and try to contribute instead of just use -- in any case, OOP just dawned on me and made sense one day while playing around with someone else's code. It doesn't seem to be explained very well in most texts I read. Instead it's a concept that had to be realized through practice and implementation -- pun fully intended. Thanks for the reading recs though guys. Going to pick up Dusty's book since Python is next in line.
Offline
I am reading the book, "Design Patterns Explained New Perspective Object Oriented Design." So far I like it.
Offline
In the real world though, you hardly get to apply pure design patterns.
Most times you apply one, and then some other team member flouts it or applies his own different pattern. MVC is the only pattern that tends to stick and not because of people consciously applying it, but only because popular frameworks like struts, JSF and spring are built on it. And if you are using struts or spring or JSF, then you are more or less using MVC (so to speak)
There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !
Offline
On my honeymoon (I am back from it for about 15 days), I read the book by David Powers on 'Object Oriented Programming' - it is focused on PHP (which I needed). Now I'm reading about Design Patterns in PHP, which is way more in-depth, but if you're an intermediate novice like me to scripting/programming, than you need to start with the basics.
At the moment I'm f.e. struggling with the concept of 'abstract classes' - I hope to tackle that concept next weekend.
Offline
Err I thought of abstract classes as being skeleton base classes where methods and variables are declared but not defined and classes are derived and define the implementations.
Offline
umm.. I am not sure about other languages, but Java does allow abstract classes to have implemented methods. In fact, if an abstract class contains only abstract methods, developers are urged to declare it as an interface instead.
There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !
Offline
In general, abstract classes are used in Java to define implementations shared between several subclasses that differ significantly in other respects. Abstract classes are unique in that they are allowed to have abstract methods and cannot be directly instantiated.
In other languages and subcultures, "abstract class" can mean the same as "interface".
It depends on where you learn it.
Offline
Mr. Google, don't mix OO programming with C++. Abstract classes generally exist in statically typed OO languages. As far as I know, they're not really needed in dynamically typed languages.
If you really want to learn OOp, C++ is definitely not a very good language to start with, despite all the respect I have for it.
INMHO
Offline
:-) The fact that there can be a discussion about the definition of an abstract class makes me feel better about myself not really 'grasping' the concept :-)
I'd have to read it again to be able to tell you all what it is according to my book, but the main question I had was 'why would you need an abstract class?'
Oh well, enough thread hijacking for me - thank you for the explanation, but carry on, lads! (I'll ask my questions when I'm actually writing my app)
Offline
@Zenlord: suppose you'd need some classes describing different kinds of fruit, then you could just write classes for bannanas, apples, melons, ... And leave them seemingly unrelated. This, however, introduces some 'problems':
* Some code may be relevant and applicable for fruit in general, independent of which kind of fruit we're talking about, this leads to code duplication.
* You can't use the power of polymorphism, a variable holding a bannana must explicitely be a bannana type, you can't just have a variable you know to be fruit. Having a variable to be 'just fruit' is especially relevant when there are some methods that are applicable to all fruit (previous point).
The solution: write an abstract class 'Fruit' and make all the others subclasses of Fruit. In this way you can put all shared code in fruit, and you can make variables which are fruits, but it doesn't really matter exactely which fruit.
Sample application: you make an app for a fruit store and you want to calculate what the custumor should pay. Then you'll enumerate the content of their basket but you don't really mind which kind of fruit every element of their basket is, you just need to loop over them and call price() on it. So you have a loop variable of type Fruit and because price() is a shared method (or the method's signature is, at least) it is in the abstract superclass.
Offline
If an abstract class is "just" a general class which others are derived and made more specific, wouldn't that make every base class an abstract class as long as all derived classes followed the "is-a" relationship?
Fruit -> Banana
A Banana "is-a" Fruit. Etc.
A section from a book I have been reading:
Abstract classes are often described as classes that do not get instantiated. This definition is accurateat the implementation level. But that is too limited. It is more helpful to define abstract classes at the conceptual level. At the conceptual level, abstract classes are placeholders for other classes classes that implement specifics of the concept the abstract class represents.
That is, they give us a way to assign a name to a set of related classes. This enables us to treat this set of related classes as one concept.
In the object-oriented paradigm, you must constantly think about your problem from all three levels of perspective: conceptual, specification, and implementation.
Last edited by Google (2010-12-16 15:04:43)
Offline
Abstract classes can also have abstract methods, that specify the parameters and return type of the method but do not implement them;
As in the abstract class fruit having a method taste(), there is no reasonable default implementation (what does fruit taste like? sweet? sour? fruity?)
so one may make that method abstract, not specifying the contents, but forcing the subclasses to have a taste().
I need a sorted list of all random numbers, so that I can retrieve a suitable one later with a binary search instead of having to iterate through the generation process every time.
Offline
Abstract classes are definitely more then just general base or super classes.
They are indeed some kind of placeholders and they unleash the full power of polymorphism. Also, it wouldn't be reasonable for a general abstract class to be instantiated because, as tlvb mentioned, they don't fully define objects. They specify some methods and only the signatures of others, again, enabling polymorphism.
The general base class defines a full fledged object on its own, an abstract class just partialy defines what its subclasses should be like and isn't a complete class on its own.
Offline