You are not logged in.

#1 2010-12-04 21:43:28

Anikom15
Banned
From: United States
Registered: 2009-04-30
Posts: 836
Website

I'd like to understand OOP better.

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

#2 2010-12-04 23:39:14

linkmaster03
Member
Registered: 2008-12-27
Posts: 269

Re: I'd like to understand OOP better.

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

#3 2010-12-04 23:40:22

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: I'd like to understand OOP better.

"Python 3 Object Oriented Programming" by one of our own, Dusty Phillips smile

Offline

#4 2010-12-05 09:53:07

xamaco
Member
From: Corsica, France
Registered: 2010-04-05
Posts: 87

Re: I'd like to understand OOP better.

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

#5 2010-12-07 09:30:35

dillesca
Member
From: Vancouver, British Columbia
Registered: 2010-11-22
Posts: 14

Re: I'd like to understand OOP better.

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

#6 2010-12-07 14:33:11

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: I'd like to understand OOP better.

dillesca wrote:

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

#7 2010-12-07 17:39:26

JezdziecBezNicka
Member
From: Cracow, Poland
Registered: 2009-12-03
Posts: 89

Re: I'd like to understand OOP better.

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 smile

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

#8 2010-12-07 17:43:06

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: I'd like to understand OOP better.

firecat53 wrote:

"Python 3 Object Oriented Programming" by one of our own, Dusty Phillips smile

smile 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

#9 2010-12-07 18:08:49

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: I'd like to understand OOP better.

JezdziecBezNicka wrote:

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

#10 2010-12-07 18:27:27

JezdziecBezNicka
Member
From: Cracow, Poland
Registered: 2009-12-03
Posts: 89

Re: I'd like to understand OOP better.

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

#11 2010-12-07 19:57:48

winch
Member
Registered: 2008-04-13
Posts: 43

Re: I'd like to understand OOP better.

I found Smalltalk, Objects, and Design a pretty good OOP book.

Offline

#12 2010-12-12 18:05:14

piffey
Member
From: Sioux Falls, SD
Registered: 2009-10-07
Posts: 54

Re: I'd like to understand OOP better.

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

#13 2010-12-13 02:27:23

Google
Member
From: Mountain View, California
Registered: 2010-05-31
Posts: 484
Website

Re: I'd like to understand OOP better.

I am reading the book, "Design Patterns Explained New Perspective Object Oriented Design." So far I like it.

Offline

#14 2010-12-13 06:05:13

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: I'd like to understand OOP better.

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)


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#15 2010-12-13 12:55:33

zenlord
Member
From: Belgium
Registered: 2006-05-24
Posts: 1,223
Website

Re: I'd like to understand OOP better.

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

#16 2010-12-13 17:00:00

Google
Member
From: Mountain View, California
Registered: 2010-05-31
Posts: 484
Website

Re: I'd like to understand OOP better.

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

#17 2010-12-14 05:37:37

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: I'd like to understand OOP better.

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.


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#18 2010-12-14 14:53:44

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: I'd like to understand OOP better.

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

#19 2010-12-14 15:55:23

xamaco
Member
From: Corsica, France
Registered: 2010-04-05
Posts: 87

Re: I'd like to understand OOP better.

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

#20 2010-12-16 08:55:27

zenlord
Member
From: Belgium
Registered: 2006-05-24
Posts: 1,223
Website

Re: I'd like to understand OOP better.

:-) 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

#21 2010-12-16 09:42:16

Ramses de Norre
Member
From: Leuven - Belgium
Registered: 2007-03-27
Posts: 1,289

Re: I'd like to understand OOP better.

@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

#22 2010-12-16 15:04:26

Google
Member
From: Mountain View, California
Registered: 2010-05-31
Posts: 484
Website

Re: I'd like to understand OOP better.

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

#23 2010-12-16 15:40:40

tlvb
Member
From: Sweden
Registered: 2008-10-06
Posts: 297
Website

Re: I'd like to understand OOP better.

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

#24 2010-12-16 15:48:05

Ramses de Norre
Member
From: Leuven - Belgium
Registered: 2007-03-27
Posts: 1,289

Re: I'd like to understand OOP better.

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

Board footer

Powered by FluxBB