Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

URGENT!! Use any UML tool to create UML DIAGRAM FOR police car and municipal pro

ID: 3845137 • Letter: U

Question

URGENT!!

Use any UML tool to create UML DIAGRAM FOR police car and municipal property.

And its importance in OOP

Using multiple inheritance when you need aggregation

How do you know when to use multiple inheritance and when to avoid it? Should a car inherit from steering wheel, tire and doors? Should a police car inherit from municipal property and vehicle?

The first guideline is that public inheritance should always model specialization. The common expression for this is that inheritance should model is-a relationships and aggegration should model has-a relationships.

Is a car a steering wheel? Clearly not. You might argue that a car is a combination of a steering wheel, a tire and a set of doors, but this is not modeled in inheritance. A car is not a specialization of these things; it’s an aggregation of these things. A car has a steering wheel, it has doors and it has tires. Another good reason why you should not inherit car from door is the fact that a car usually has more than one door. This is not a relationship that can be modeled with inheritance.

Is a police car both a vehicle and a municipal property? Clearly it is both. In fact, it specializes both. As such, multiple inheritance makes a lot of sense here:

Steering wheel Door Car Tires

Explanation / Answer

Here are the java classes and interfaces:


class BaseObject{
    long id = 0;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }
}

class SteeringWheel extends BaseObject{
}

class Door extends BaseObject{
}

class Tyre extends BaseObject{
}

class Car extends BaseObject{
    private List<Door> doors;
    private List<Tyre> tyres;
    private SteeringWheel steeringWheel;
    public List<Door> getDoors() {
        return doors;
    }
    public void setDoors(List<Door> doors) {
        this.doors = doors;
    }
    public List<Tyre> getTyres() {
        return tyres;
    }
    public void setTyres(List<Tyre> tyres) {
        this.tyres = tyres;
    }
    public SteeringWheel getSteeringWheel() {
        return steeringWheel;
    }
    public void setSteeringWheel(SteeringWheel steeringWheel) {
        this.steeringWheel = steeringWheel;
    }
}

class PoliceCar extends Car implements MunicipalProperty{
}

class StreetSign extends BaseObject implements MunicipalProperty{
}

interface MunicipalProperty{

}

Import this code into your eclipse and follow this:http://fuzz-box.blogspot.in/2012/09/how-to-generate-uml-diagrams-from-java.html to generate UML diagram.