Im pretty green when it comes to designing a large scale application architecture, and have a question on the way I should go with it.

Just for an example, to ask the direction I should take my design in, consider this:

A parking lot manager has control over everything that happens in his parking lot. He is able to move cars to different parking spots if he wants, allow or dont allow new cars to park in his lot, etc....

So if the parking manager wants to move carOne from parking spot A to parking spot B, can the parking lot manager simply get in and move it him self, or should he be required to ask the owner of the car to move it for him.

To me, it seems like doing the latter, would require duplicate functions to accomplish something. IE Parking lot manager asks driver to move car, than driver moves car. aka 2 calls to accomplish one task. Although this seems wrong to me, it feels as though it better encapsulates all of the rules of the parking lot.

So to go about that in code...
You could say that Class B is composed of Class C and Class D while Class A consumes Class B. So you would have calls like a.b.doSomething(i){this->c.doSomething(i) or his->d.doSomething(i)}. Aka the multiple calls.

but if you had Class A which consumes Class C and class D you would have a.c.doSomething(i) or a.d.doSomething(i) and thats it.

I hope this makes sense and someone can guide me in the right design direction, or at least provide an opinion. Thanks

Recommended Answers

All 3 Replies

The manager should use the interface provided by the car. Even if there would be an extra call, it better encapsulates and is easier to maintain and debug, if only one function controls the movement of the car. So if you make different type of parking manager, you can use the interface of the car in different ways for each manager.

Im sorry, it seems like I might not of explained very well, or I just don't under stand your response. Here is a more clear picture, for just example.

class A
{
    public:

    B b;
}

class B
{
    public:

    void printHelloWorld()
    {
        _c.printHello();
        _d.printWorld();
    }

    private:

        C _c;
        D _d;

};

class C
{
    public:

        void printHello()
        {
            cout << "Hello";
        }
};

Class D
{
    public:

        void printWorld()
        {
            cout<< "World";
        }
};

int main()
{
    A a;

    a.b.printHelloWorld();
}

//OR if A just owned a C and D

int main()
{
    a.printHelloWorld(); //{_c.printHello _d.printWorld}
}

So if i do it the first way, I have to call PrintHelloWorld which inturn calls another function PrintHelloWorld.

The second way is called composition pattern and should be the preferred way.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.