Closed pletcher closed 8 years ago
@pletcher any specific on how to be more precise with the intro?
@StevenNunez, i think you probably will agree with @pletcher here but feel free to discuss on this.
I think what I'm going for is that OO is a way of organizing code according to shared actions and properties, and less about making our code look like the real world.
What I'm trying to avoid is a situation where students are reluctant to implement, e.g.,
class Honker
def honk
puts "honk!"
end
end
class Car < Honker
end
class Duck < Honker
end
This is a contrived example, but I just mean for it to show how programming is nothing like the real world.
I'd leave the connection to real world objects out of it completely. I find it much more useful to think of classes in terms of responsibilities. I don't know how deep you want to go into what that means. What a single responsibility for a method means vs. what a single responsibility for a class means. Having a single reason to change vs. "doing" one thing.
I think a good way to get into this is to build a few objects that collaborate with each other. Maybe something like:
class Dog
attr_reader :name
def initialize(name)
@name = name
end
end
class Human
attr_reader :name
def initialize(name)
@name = name
end
end
class NotificationDispatch
attr_reader :notifier, :recipient
def initialize(notifier, recipient)
@notifier = notifier
@recipient = recipient
end
def notify(message)
puts "#{notifier.name} says #{message} to #{recipient.name}"
end
end
fido = Dog.new('fido')
bob = Human.new('Bob')
notifier = NotificationDispatch.new(fido, bob)
notifier.notify("GIVE ME FOOD")
This is a wacky example, but something like this might work. @pletcher
@bigblind agreed 100% -- the challenge is, I think, working up to the idea of single responsibility without inundating beginners with programmer-speak :)
@StevenNunez I like that example. I wonder if we can just rewrite "Object oriented programming, or OOP, is an extremely useful programming paradigm in which we can organize our code according to how real-world objects might interact with one another" so that it instead reads, "Object-oriented programming, or OOP, is a programming paradigm in which we organize our code according to shared behaviors and properties. For example..." and then maybe a pseudo-code example of what you have above?
@pletcher I like it but it doesn't sound as nice as the first one even though it's more accurate! Is there a better way of saying "shared behaviors and properties"?
@StevenNunez yeah, that's the thing. Maybe we can talk about "organiz[ing] our code around things (objects) and what they do"?
We can put the misperception that "Objects help you model the world" and show the limitations of that. Something like "If we only limit our objects to entities in the real world, the limitations will start jumping out at us." Maybe follow up with something like "Imagine a telephone call between 2 people. Sure, the PEOPLE are real, but what about the phone call? If we think about the phone call through OOP, we can model it too! A phone call has a caller
and a receiver
, a duration
, and even a cost_per_minute
. In the real world, it's not a real thing, but in programming IT IS!" @pletcher
That seems perfect -- wanna pop that into a PR?
@pletcher githttps://github.com/learn-co-curriculum/oo-basics/pull/24 Let me know what you think.
WOOT!
The sentence "Object oriented programming, or OOP, is an extremely useful programming paradigm in which we can organize our code according to how real-world objects might interact with one another" is at best an oversimplification and at worst a confusing limitation on the possibilities of OO.
One of the most confusing things about OO is it's attempt to mirror the real world, but that's not really what OO sets out to do, right?
OO is all about mnemonics and ergonomics, not representations per se (I think, anyway).
So anyway we should be more precise with this introduction.