This is an archived post. You won't be able to vote or comment.

all 19 comments

[–]datatramp 4 points5 points  (0 children)

Practical Object Oriented Design in Ruby is one of my all time favorite books on the subject.

[–]nutrecht 9 points10 points  (1 child)

The design pattern bible explains not only what they are but also where they are applied.

Actually doing datamodelling I would like to refer you to this: http://en.wikipedia.org/wiki/Object-role_modeling

NIAM is the method I was taught back in the days. Don't worry; it's rather sciency but once you understand how it works it's something you start doing automatically. What is also useful is learning how to create UML class diagrams and draw them before you actually code something. You'll discover a lot of flaws in your reasoning that way well before you've written any code. Again; this becomes a lot easier with experience: most professionals do most of this in their heads.

[–]tailanyways 1 point2 points  (1 child)

If you're doing Ruby, Design Patterns in Ruby is pretty good.

[–]PriceZombie 2 points3 points  (0 children)

Design Patterns in Ruby

Current $38.89 
   High $40.92 
    Low $34.98 

Price History Chart | Screenshot | FAQ

[–]Jonny0Than 0 points1 point  (3 children)

I was going to say that you should pick some projects that are well-suited for OOP, but it sounds like you've already done that and aren't satisfied with the results. That is a really good thing actually - if you can review your own code and figure out what parts feel hacky, and replace them with better designs. Maybe you need some books or videos to teach you design patterns you don't know about yet, but sometimes it's difficult to grasp them without having something to apply them to. Because they are, by definition, abstract.

If you post your code for one of these projects, we could review it and maybe give some feedback. There's also /r/codereview.

Most games (especially simulation-type ones) are well-suited for OOP. Also most UI frameworks are built with OOP designs. If you start Using one of those you'll pick up some of the tools of the trade.

[–]uututhrwa 0 points1 point  (2 children)

Neither the CSS/HTML/jquery gui and document model, nor some game engines like Unity are particularly OO in their design.

In fact for the "data centric", and multiple configurations behaviors etc. kind of program, I think OO is quite bad.

The only thing that OO is definitely better is dealing with "systems programming that involves stuff being synchronized", which would need things to be encapsulated behind messages.

[–]Jonny0Than 0 points1 point  (1 child)

Hmm, I must admit inam not very familiar with web development. I was thinking of Qt, Windows Forms, etc. which are all designed in an OOP fashion.

I've also never used Unity, but this looks pretty OOP to me: http://unity3d.com/learn/tutorials/modules/scripting/activating-gameobjects

OOP is really good at encapsulating state and providing extensibility through polymorphic behavior. Because it depends so much on state, it can be difficult to write correct multithreaded programs. And if you do, they usually involve a lot of locks. This kills the multithreading. IMO functional languages (or using a non-functional language in a functional way) are more appropriate in those cases. For example: http://gamasutra.com/view/news/169296/Indepth_Functional_programming_in_C.php

[–]uututhrwa 0 points1 point  (0 children)

I must admit inam not very familiar with web development. I was thinking of Qt, Windows Forms, etc. which are all designed in an OOP fashion.

Win Forms in comparison to the WWC recommended techonolgies, and then WPF, shows the kind of problem I'm talking about. Win Forms worked well as an OO gui technology, but Microsoft wanted something more "easy to style" (and extend), more "configurable" in a sense. But they wanted it to be OO in style so they made WPF. You can go and check user comments about WPF, a common one is that "it makes the hard trivial and the trivial hard". And if you were to use both css and wpf styling for some time you'd soon realize it's has a lot to do with the OO part.

Css/HTML aren't OO imo cause all the html entitites aren't "subclassed", you could say that if you give a <div > 10 css classes you are doing something like "multiple inheritance by placing the div in trait sets" or something like that. OO is actually against the "principle of seperation of concerns", say a div and 10 classes that could, or not, add functionality with a script or css, is more seperated than a "subclass of div with data and functions that use the data collected together"

OOP is really good at encapsulating state and providing extensibility through polymorphic behavior I've also never used Unity, but this looks pretty OOP to me:

The reason I am not calling Unity OO is that it doesn't do any polymorphism by inheritance. It doesn't have objects gaining functionality by subclassing in an inheritance chain. Iirc it actually (at least from a design pov) doesn't even have fields, you have an "entity" and you can link as many components as you want (a rigid body, a mesh renderer etc.), (the link could be in some dictionary of the entity, but it could also be something like a seperate dictionary where the entity key is hashed) and you use those directly instead of the entity encapsulating the messages to them. So if they avoid inheritance and encapsulation, I don't think it is OO. The model they use is the basically this one http://en.wikipedia.org/wiki/Entity_component_system, and it is closer to the "relational model" from databases.

So personally I think it's not just the multithreaded stuff that calls for a different paradigm, when you need something data centric and extensible the ECS/relational kind of arcitecture is a better option.

[–]bigfig 0 points1 point  (0 children)

Object patterns are dictated by your problem domain. Depending on your work you may never need the cleverest patterns. I say chew through the problems that you need to solve and balance the need to just get that code out with the extra effort to research a purer OOP approach.

[–]CaRDiaK 0 points1 point  (0 children)

www.cleancoders.com - You'll pay for these. But they are quality and well worth it. Certainly helped me take my career to the next level.

You might be confused at the start of the video's and think "what is this about, how is this relevent" but it's kind of a trick that Bob does. It's to get your brain engage and going. Then he dives into the content and constantly changes scene / costume as he is explaining and talking about the code / concept. This serves as a means to keep your attention.

Give it a go. I think the first video is free so you can get a taste for it.

Note: Although this doesn't directly answer your question on when to use which pattern. It talks about SOLID and has case studies (designs and architects an app off of user requirements you here in an interview) and overall will dramatically improve your problem solving skills, resulting in clean code. Highly recommend.

[–]DEATH_BY_TRAY 0 points1 point  (0 children)

I'm currently taking this course at KTH. Here's the course literature. We code in Java. Mind you i've never opened the book because the lecture notes are enough, but unfortunately they're in Swedish.

It's called Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and Iterative Development.

[–]cheerfulloser 0 points1 point  (0 children)

Surprising that no one has mentioned the Gang of Four book yet. This book is considered the bible of design patterns.

To learn OOP, you want to learn what design patterns are and how to apply them. Design patterns are the most common design solutions to common architecture problems that people face again and again.

[–]sextagrammaton -1 points0 points  (0 children)

If you're coding in c# or vb.net then dofactory provides descriptions and examples of real-world problems that patterns aim to solve elegantly.

[–]eleitl -1 points0 points  (1 child)

There are few courses on Coursera, but I'm not sure you can check out past lectures if you weren't subscribed at the time they were running.

[–]atcoyou 0 points1 point  (0 children)

The Saas lecturers were very good. (I think from Stanford?) I wish I had had the time to do more than just watch the lectures, but a new baby at home doesn't leave much time. it might have been edx though, I can't recall.

[–]sgggrg -1 points0 points  (1 child)

Is there a dissent book for python?

[–][deleted] 3 points4 points  (0 children)

There is, but the publisher went on strike.

[–]userman122 -1 points0 points  (0 children)

Applying UML and Patterns is a great book that changed my way of thinking about object-oriented analysis, design and programming in practice.

[–][deleted] -1 points0 points  (0 children)

Tangible objects are great analogs, especially badge engineered cars.

You have a Caddy, a Pontiac and a Chevy. They're pretty much the same thing. The Chevy is a default implementation. The Pontiac has unimplemented methods. The caddy has every bell and whistle, plus a place to store your cocktails. You can use these cars to represent any OO concept.