"The Clean Code Talks -- Inheritance, Polymorphism, & Testing"

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
80,101
Loading...
Alert icon
Sign in or sign up now!
Alert icon
There is no Interactive Transcript.

Uploaded by on Dec 4, 2008

Google Tech Talks
November 20, 2008

ABSTRACT

Is your code full of if statements? Switch statements? Do you have the same switch statement in various places? When you make changes do you find yourself making the same change to the same if/switch in several places? Did you ever forget one?

This talk will discuss approaches to using Object Oriented techniques to remove many of those conditionals. The result is cleaner, tighter, better designed code that's easier to test, understand and maintain.

Speaker: Misko Hevery

Category:

Science & Technology

Tags:

License:

Standard YouTube License

  • likes, 17 dislikes

Link to this comment:

Share to:

Top Comments

  • I agree with jsmartin00, these should be available on a different channel so I can subscribe!

  • @jihedamine It's not about African people, it's about African swallows -- a Monty Python reference, which 80% of the geek viewers of the video are likely to get. (The "Norwegian Blue" in the example refers to another Monty Python sketch about a dead parrot.)

see all

All Comments (85)

Sign In or Sign Up now to post a comment!
  • 32:38 Our code is full of this kind of replicated crud. We're eradicating it as we can using these methods.

  • Beautiful :)

  • @Tiddo1000 what you should do is you create a facade (i recommend using DI also) .. consisting of every object toggled by the flags .. 1 flag is for 1 inheritance hierarchy, so if you have multiple flags, that means your class have too many responsibility .. divide it to multiple responsibility and at the last stage, create a facade to aggregate all those responsibility into 1 class ..

  • This lesson is so sueful for me. I've changed my mind through this film in my programming. Thank you.

  • Great video

  • i'm just a few minutes in, but let me speak my mind: re-readability is not a religion; How many times have you actually recycled your code?!

  • @urMamaMuthaSukka That is is correct, it is not very OO. But taking the OO approach is also brittle, just in a different way. As I pointed out, if we need to implement toString() then we have to modify every class, there is no getting around that when you use inheritance to achieve polymorphism. Haskell solves the "add a function later" problem by using type classes for polymorphism, this is a much less brittle approach. It is a bit like using interfaces and the adapter pattern in OO.

  • @jystic That's not very OO. Objects should have specific behavior. If the behavior of the object changes on state, then it's obvious that behavior belongs in it's own object. Your suggestion leads to brittle design, which is harder to maintain, test, and extend.

  • It's really easy to remove all if statements from your code. Take this snippet for example: if(a > b){ c = a - b; } Replace this bad if statement with the following for good, clean code: while(a > b){ c = a - b; break; } If statements = gone
  • @Tiddo1000 One way to achieve this is to use the decorator pattern to decorate your conditional with another conditional.

Loading...

Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more