#1,556 in Computers & technology books
Use arrows to jump to the previous/next product

Reddit mentions of Object Design: Roles, Responsibilities, and Collaborations

Sentiment score: 2
Reddit mentions: 2

We found 2 Reddit mentions of Object Design: Roles, Responsibilities, and Collaborations. Here are the top ones.

Object Design: Roles, Responsibilities, and Collaborations
Buying options
View on Amazon.com
or
Specs:
Height9 Inches
Length7.25 Inches
Number of items1
Weight1.38009376012 pounds
Width1 Inches

idea-bulb Interested in what Redditors like? Check out our Shuffle feature

Shuffle: random products popular on Reddit

Found 2 comments on Object Design: Roles, Responsibilities, and Collaborations:

u/high_hobo ยท 1 pointr/javahelp

I actually ended up helping a few people on this exact problem. Small world, eh?

The way I would have designed it would be to start at how I wanted to use the system. This may seem odd and fairly abstract, but can lead some detail as to how it can be done:

Car entrant = new Car("Ford Fusion"); // or whatever
Spot spot = carPark.park(entrant);

if (spot == null) {
System.out.println("Could not find a spot for the car!");
} else {
System.out.println("Car was parked at: " + spot);
}

This tells me I automatically need a few things.

  1. We need a Car class
  2. We need a Spot class
  3. We need a CarPark class
  4. In the car park class, there is a method to park a Car and returns the Spot that the car was parked into; if available, otherwise null.

    So what was the purpose of this exercise? Merely to show one way to approach the problem. I'd personally say that the code above is fairly clean and understandable, would be a good way to have the final implementation be written.

    ---

    From here you have a few options. One I found to be quite nice was having a Floor class that contains all the Spots available for that floor. This kinda makes sense, as multiple Floors make up a single CarPark and will usually be very very similar.

    Then as for parking the car, a modified Visitor Pattern was used. Which might seem a little confusing at first. However, think of it in the real world. A car will keep visiting available floors until it either runs out of floors or finds a spot to park. Just as you would do as you are trying to find a spot to park in.

    So in the end it could look like:

    public class Car {

    public Spot visit(Floor floor) {
    // find suitable empty spot
    }
    }

    public class Floor {

    private final List<Spot> spots; // all available spots

    }

    public class Spot {

    // type, availability, etc...

    }

    public class CarPark {

    private final List<Floor> floors;

    public Spot park(final Car vehicle) {
    for (Floor floor : floors) {
    Spot spot = vehicle.visit(floor);
    if (spot != null) {
    return spot;
    }
    }
    return null;
    }
    }

    Very bare-bones implementation, but a good starting block. Here, I designed it with the real world in mind. Car, CarPark, Spot, these are all tangible real-world objects. And a CarPark is basically a bunch of Floors and each Floor has certain Spots available to it.

    This design here should mirror the real world fairly nicely. That is the purpose of OOP. Its to you can say things like carPark.park(car); and understand what that does.

    ---

    Hopefully you understood the steps I took here. If anything was too confusing, not explained in enough depth or anything, feel free to ask.

    As to learning this stuff, here are my recommendations in order of importance:

  5. Write more programs like this. 'Simulations' like this are often based off of the real world and have a very nice OOP model.
  6. See if your university/college offers a Software Design class. These are based off of OOP like 99% of the time and go over patterns like Visitor, Adapter, Singleton in far more depth as well as teaching you how to come to that conclusion.
  7. Check out a few books. Design Patterns is fairly in depth. Personally, I have a few OOP books and one I found to be quite nice is Object Design: Roles, Responsibilities and Collaborations

    Hopefully this helped clarify a few issues here.
u/pmorrisonfl ยท 1 pointr/compsci

These are all excellent. I'm a particular fan of the DDD book.

I really liked Kent Beck's Implementation Patterns. I've only thumbed through Object Design by Rebecca Wirfs-Brock, but she's brilliant, and the book has a good reputation.