11 Comments

Stop using Circle/Square/Rectangle, People/Employee, Car/Model  examples for models or example on how to use Object-Oriented Principles or any example at all.

There is plenty of "Open" model that you can use. Here's a simple list for those who needs inspiration:

  • Blog (Posts, Comments, Authors, etc...)
  • E-Commerce (Invoice, Order, Customer, Warehouse, Inventory, etc...)
  • Auction (Auction, Seller, Buyer, Reputation, etc....)
  • Bank (Account, Transactions, Customer, etc...)
  • News site (Article, User, Approver, etc...)
  • And so many more

Unless you are explaining what is OOP to total beginner that never did any of this, you should use more advanced model to explain practices, design patterns or anything else. Otherwise, we'll keep on babbling on stupid model how a Square is a Rectangle and so on.

The time has come to stop using 1st grade model to explain advanced concept. Most people should be able to easily pick one of the model I've shown above and display one element of the model to easily make it available to everyone.

Who's with me?

Comments

Comment by Dani

I think you are confusing OO principles with domain modeling.

Dani
Comment by guigouz

Where's the inheritance in your examples ?

guigouz
Comment by Paul Jackson

Are we talking about the initial introduction to the concept or carrying the first model through an entire class? These are two different things.

First get the student's head wrapped around the underlying concept (inheritance, parallelism, whatever) with as simple and unobtrusive a model as possible. Animal=>dog/cat.

Once that's done, you introduce a more complex, real-world example to make them think about the practical applications of the concept -- but the critical piece is they've already understood the concept from the simple example and now they're ready to apply it.

Carrying dog/cat through an entire OO course would be counter-productive because then the student IS distracted by the whole "why would I do that with a cat"-question. Just as they'd be distracted up-front by too complex a model.

To go back to my parallel-programming example, because that's most recent in my mind, I first teach the concept with a bogus method that's just described as "business logic". But as we get further and further into the topic, I bring in real world applications and examples.

Paul Jackson
Comment by Philip

"I think we are all smart enough to wrap our head around how an "Order" have "Product" and that "Discount" are applied to "Product"."

The problem with this example is it's too complex. An Order doesn't have many Products. It has many LineItems. A LineItem references a Product, but has it's own price (set at the time the order was placed). Now suddenly Discounts apply to both products (when a user is browsing) and apply to LineItems (once a user has ordered). And right about here someone asks "how do you handle buy 2 get 1 free discounts instead of just 10% off?" and you're no longer talking about OOP you're talking about modeling a very specific situation.

Otherwise I agree with you. No one models Dogs/Cats that run/sleep/eat. Make it something people can relate to. Authors/Blogs/Posts/Comments is a good one.

Philip
Comment by myerman

Whenever I've used the super simple "real life" models (like Car, Dog, whatever) most of the people in the workshop get it right away, but then you get to this point where you're doing something unnatural/unworldly to your examples that make everyone go...WTF?

For example, if you try to subscribe() to a Dog, or give the dog moreLegs(), etc. You're fine if the dog is about to run() or sleep() but then everyone gets into a discussion about what dogs can/can't do. They get all locked up.

I agree-much better to model on a specific domain (if you can) that follows a business process or software paradigm.

myerman
Comment by Maxime Rouiller

I totally agree with you that you must have a domain that is understandable by those who are receiving the examples.

What about those I already gave? Anybody able to model a Blog? BestBuy? eBay? CNN?

Those were the sites I used for those examples. They are the most common models that every programmer should be able to wrap his head around in very little time.

And whatever if the domain is not "exactly perfect". Who cares? At least I'm not trying to persist a "Square" to a "SquareService" through a DI of a "ISquareRepository".

I think we are all smart enough to wrap our head around how an "Order" have "Product" and that "Discount" are applied to "Product".

If people are not able to understand this small model... they would technically be brain-dead and unable to work in society.

I don't say that you should understand the "BestBuy business model" or "eBay business model". The simple goal is to bring everyday model that people use daily/weekly and show them how they can work togheter.

Maxime Rouiller
Comment by Paul Jackson

That's fine if you're training within a known industry, but typical OO training occurs in classroom environment with students from a variety of industries -- if the example is too specific, then the students have to first learn the example instead of concentrating on the topic you're actually trying to teach.

I'm facing this right now with regard to parallel programming extensions in .Net 4. The current examples tend toward things like manipulating matrices in multi-level arrays. But my student base writes primarily line-of-business applications -- they really don't have cause to do that sort of thing on a regular basis, so it's a non-productive demo.

Instead, I show them a bogus method that does a bunch of random math -- I explain it as "this is a big, ol' hunk of business logic". The student can then pay attention to the improvements parallel programming makes, rather than trying to understand something meaningless to their typical work.

Paul Jackson
Comment by Maxime Rouiller

I'll have to agree that the goal of those model are not to build the whole system. It's however more easy to show how to make a good Liskov Substitution Principle with "Invoice" sent to and "InvoiceService" which is built with a "IInvoiceRepository". This is more useful to learn and memorize than something about Car/People/Shapes.

The goal here is mainly to adapt the current field you are working in (Finance, E-Commerce, ISV, etc.) to something a junior could understand.

The reasons I took those simple model up there is because of A) Their simplicity B) Modularity C) Variety of objects visible inside.

If you are looking to show LSP for testing and mocking, maybe a simple "Blog Model" is enough to display it on an object "Post". However, if you are looking to display a Pipeline pattern, it might be more easy to display "Discount" applied to a "Product".

Maxime Rouiller
Comment by Paul Jackson

I have to agree with Astrobe.

Using the "stupid" (simple) examples allows the student to focus on what's really being taught. The example should be as innocuous as possible and not take any of the student's attention away from the fundamental concept.

Paul Jackson
Comment by Astrobe

And I'm not.

These models are like "Hello World". Everyone have seen and done them *ad nauseam* so people can focus on the part that's really interesting or difficult. For instance, it is really best to pick "a Square is NOT a Rectangle (in most OO geometries)" in order to explain Liskov's principle.

Astrobe
Comment by fede

I'm with you man.

fede