File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes OO, Patterns, UML and Refactoring and the fly likes OOP Examples and Exercises Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "OOP Examples and Exercises" Watch "OOP Examples and Exercises" New topic

OOP Examples and Exercises

Sathya Srinivasan
Ranch Hand

Joined: Jan 29, 2002
Posts: 379

I have been asked to train some resources in my client company in OOP (they are mainframe programmers).

I am trying to gather material to

1. Order the OOP concepts such that the concepts are unravelled gradually.
2. Exercises and examples that can help them practice what I preach.

I have been Googling for quite some time but would appreciate it very much if you could share your favorite bookmarks/references/books in this regard.


Cheers, Sathya Srinivasan - SCJP 1.2, SCWCD 1.2, SCMAD 1.0
Co-Author of Whizlabs SCMAD Certification Exam Simulator and SCMAD Exam Guide Book
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
You might consider using OOP Demystified to back up your training.

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Sathya Srinivasan
Ranch Hand

Joined: Jan 29, 2002
Posts: 379
Thanks. The review looks good. I will check it out.

Anything else, fellows?
Al Korov

Joined: Sep 11, 2004
Posts: 21
I like reading the "How my Dog learned Polymorphism" story in JavaRanch's Campfire Stories section, everytime I read it. I wish they had some more like them.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Look to the gurus like Robert Martin's Agile Software Development for OO principles. If you are comfortable with the ideas, you'll be able to find examples that apply to your class in real life. That's how I wound up making this for my team: The DIP (Sorry, I hate the way I converted PowerPoint to HTML.)

Also (intended to be) fun: Knight's Principles and Law of Demeter
[ September 11, 2004: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Sathya Srinivasan
Ranch Hand

Joined: Jan 29, 2002
Posts: 379
Thanks for the links..

I am currently reading the Martin book as a part of Design Pattern Study Group of NY. I surely will be trying to incorporate the concepts in the training.

I am looking more for a good explanation of the basics and some simple examples/exercises that I can give to the attendees. This is where I cannot find much data.

I looked at the "OOP Demystified" book and found one issue with the intro (which I find common in almost all other books).

The book begins with a valid question - Why bother changing to OOP? Then it says that OOP is better because it is modelled after nature and that it can adapt to changes better than other methodologies.

But it does not say how other models cannot adapt as much as OOP. I am sure I will be asked this question by my audience, who are rooted in Structured Programming (AS/400, COBOL, and alike).

With such structured programming languages showing signs of OOP (like Object COBOL and RPG IV), how can I convince them that a pure OOP language (like Java, Smalltalk, etc.) is better suited than them?

As OOP techniques have become more and more commonplace, most of the books assume implicitly that OOP is the best option, but never bother explaining how.

Any explanation in this regard would be most welcome.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
What's different about OO? Great question from a good procedural crowd! I've seen OO taught as "everything you know is wrong, here's the only right and good thing" and it turned people off, so treat the question with respect.

With procedural stuff, you most often have data structures and a collection of routines that work on the structs. With functional decomposition you can wind up with a bunch of modules that work on the same structure. The first version of such a system may be a thing of beauty, but it is likely to be fragile to change. For example, a change to a structure may impact many modules and every mod is an opportunity to mess up and introduce bugs.

OO is just a different way to organize code. If your procedural folks are into sophisticated information hiding and modularity they might claim the only thing really new to them is inheritance. But when you "get" OO it leads to very different decisions about what code belongs together and what does not.

One way to see OO is taking a structure and wrapping it in code. Only the code in that class can ever touch the structure. It's impossible for some new module to muck up the data. The protective layer of code simply won't allow that kind of change. If your guys got information hiding, they'll get encapsulation pretty fast.

Another way is to see OO is to focus on behavior. An object can offer the rest of the world a certain set of behavior and other objects can use it. In this view you never think about the structure the object might (or might not) be hiding, only what it can do for you.

A fun aspect is you can anthropomorphise objects - talk about them as if they were people. Try message passing between people. Hand somebody a card that says "Turn off the light". Give somebody else another task. Talk about what they are able to do and what they know. Get some tasks that involve several people. And let us know what you come up with, cause I want to try it too!
Sathya Srinivasan
Ranch Hand

Joined: Jan 29, 2002
Posts: 379
Hi Stan,

Thanks for the great ideas! I will definitely try them out. I will definitely be posting my experiences and some materials that I come up with in the Ranch once this is over.
Sujatha Kumar
Ranch Hand

Joined: Jan 05, 2004
Posts: 134
Hi Sathya,

"Object Oriented Thought process" is an excellent book covering the fundamentals.

You may like it too...


Sathya Srinivasan
Ranch Hand

Joined: Jan 29, 2002
Posts: 379
I browsed through the OOTP book in the friendly neighborhood B&N, but to be honest, I was not impressed with the organization of the book.

The couple of chapters that I went through (mainly about abstraction, composition) did not seem to cover the concepts clearly. Maybe I was having a high expectation on the book looking at the title. The title suggested to me that it would tell me how to think in terms of objects, but ended up to be another book explaining the standard concepts (not that it's bad though).

I also looked at

Object Thinking, Dave West
Object Technology: A Manager's Guide, David A Taylor

without much success.

Let me also mention here that the books mentioned above probably have a difference audience and may satisfy them quite nicely. So don't take my comments as putting down these books.

I am currently eyeing

Object Design: Roles Responsibilities, and Collaborations
by Rebecca Wirfs-Brock, Alan McKean

Designing Object-Oriented Software
by Rebecca Wirfs-Brock, Brian Wilkerson, Lauren Wiener


Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and the Unified Process (2nd Edition)
by Craig Larman

I have the third book and it looks at OOP mostly from UML perspective.

Has anyone read or used the first two books? If so, can you please let me know if it's good?

Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Originally posted by Sujatha Kumar:
"Object Oriented Thought process" is an excellent book covering the fundamentals.

Mmm, I feel like the explanation of association, aggregation and composition topics in the book is a bit difficult to understand... Those topics are well-explained in Fowler's UML Distilled book as well... As for me, I prefer Fowler's book much more than "Object Oriented Thought process"...

Just my 2 cents...

Co-author of SCMAD Exam Guide, Author of JMADPlus
Warren Dew
Ranch Hand

Joined: Mar 04, 2004
Posts: 1332
I recommend Chapter 2 of [i]The C++ Programming Language{/i] by Stroustrup. It's as applicable to Java as C++, and it will start with things your audience is familiar with, and build up to and through object oriented programming, showing how OO will help make their jobs easier.
I agree. Here's the link:
subject: OOP Examples and Exercises
It's not a secret anymore!