4 Replies - 2140 Views - Last Post: 24 February 2013 - 06:21 PM

#1 carnivroar  Icon User is offline

  • D.I.C Regular

Reputation: 28
  • View blog
  • Posts: 384
  • Joined: 18-September 11

My OOP exercise

Posted 08 February 2013 - 10:12 PM

What do you think of this OOP exercise/project that I created?

I assigned it to a friend who was struggling with Java, and now I am thinking of making it public on my website.

Any suggestions?

http://rcs.hostoi.co...opexercise.html

Site is down but here's the assignment:

Spoiler

This post has been edited by carnivroar: 09 February 2013 - 11:50 AM


Is This A Good Question/Topic? 0
  • +

Replies To: My OOP exercise

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4421
  • View blog
  • Posts: 12,286
  • Joined: 18-April 07

Re: My OOP exercise

Posted 09 February 2013 - 12:52 AM

Seems fine to me. Very simple and straight forward with just enough detail and without a lot of complicated jargon.
Was This Post Helpful? 0
  • +
  • -

#3 carnivroar  Icon User is offline

  • D.I.C Regular

Reputation: 28
  • View blog
  • Posts: 384
  • Joined: 18-September 11

Re: My OOP exercise

Posted 09 February 2013 - 04:20 PM

What do you think of my solution? Is it good OOP design?

This post has been edited by carnivroar: 09 February 2013 - 04:21 PM

Was This Post Helpful? 0
  • +
  • -

#4 TheKirk  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 58
  • Joined: 10-February 13

Re: My OOP exercise

Posted 10 February 2013 - 11:49 PM

In my opinion you can only really test if someone understood Object Oriented programming when they did are larger project. But this seems like a rather good exercise for new people. Saving it for if I need to help some one with Java again.

The code (your solution) looks fine to me, it's a good example on class inheritance. Good work!
Was This Post Helpful? 0
  • +
  • -

#5 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: My OOP exercise

Posted 24 February 2013 - 06:21 PM

I like your exercise. Well thought out and well put together. I have a couple of semantic observations from your definitions at the top, however. Interface implementation is simply a form of inheritance. For example, a Dog class implements an iAnimal interface. The Dog "is an" Animal, same as if it inherited a concrete Animal base class. Also, while your example indeed uses Composition, Composition is a specialized form of Aggregation. Aggregation is the "has a" relationship.

An example of aggregation might be that a Case object has 0-12 Bottle objects. The Bottle object may or may not be associated with a Case. Now, a Chessboard object has 64 Square objects. There is no concept of Square that is not a part of a Chessboard, so that's Composition. The point about composition is that the associated objects share a lifetime, whereas in Aggregation they do not necessarily do so.

An interesting point is that context will often define which is which. Suppose you have a Car. The Car has four Wheels. Now, if you're in a car factory, you would think of the wheels as inseparable from the car; once you deliver the car you deliver the wheels. However, if you are in a junkyard, this is not the case. So, the factory would use composition and the junkyard would use aggregation.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1