I have a test today at 5:30 est. And I have a couple questions
The test is over inheritance, polymorphism, UML, and File stuff like seekg, tellg, write and read methods etc.
Im am golden on everything except UML.
I understand how to make UML diagram with the associations etc such as aggregation, composition, dependency, inheritance etc.
My problem is that how to go from a UML diagram to at least a header file.
For example say you had a dependency relationship between two objects.
- I assume you would pass one object into another via a constructer maybe.
I know how to show inheritance and composition from uml, however, aggregation, dependency, and association are a little sketchy going from uml to source code.
I have a feeling on the test he is going to give us a question and ask us to make a Class diagram of it and then create the header files for each.
Ive looked on this site and also I have googled the subject but I cant seem to find anything talking about how to go from uml to source.
Its pretty much for desighing a program or whatever. So you draw little boxes that represent classes. Then you draw lines to the boxes that represent certain relationships. for example if you have a teacher and a department class... You could say that a department is made up of teachers. So you could maybe use an aggregate relationship. This meaning if you were to destroy the department, the teachers in the department would still be alive.
From what I see, it looks like classing at it's most reasonable form. This is what I am TERRIBLE at. As a matter of fact, if this is what I think it is, I'll have to think you a later time. :D
Its pretty much for desighing a program or whatever. So you draw little boxes that represent classes. Then you draw lines to the boxes that represent certain relationships. for example if you have a teacher and a department class... You could say that a department is made up of teachers. So you could maybe use an aggregate relationship. This meaning if you were to destroy the department, the teachers in the department would still be alive.
That is only a drop in the bucket to describe UML. UML is a standardized notation for describing Business Processes, Systems, and Interactions. Class diagrams are structure diagrams so they detail what things (objects) should exist in the system and their relationships. Different diagrams are suited to different roles and different purposes. It sounds like you are taking an Object Oriented Design w/ C++ course which I highly recommend to anyone using C++. To this day I'm shocked at how many C++ programmers there are out there that do not use UML... I'll set you up with some examples a little later, my frosty is melting and I have a design meeting to run to...
Aggregate Class - Think of an aggregate class as an Object that consists of other class objects. The other objects all exist on their own apart from the Whole class, but when they are aggregated to a whole, they are used to comprise that class. So say the class Team was deleted, the other classes would live on without it. It's important to remember with Aggregate that the classes that make up the whole class must exist outside of it.
So let's say we have a class called Team. And we have 4 other classes called Developer, QaAnalyst, Analyst, & DumbBoss. We can aggregate in the following manner:
1 2 3 4 5 6 7 8 9
class Team
{
public:
Developer Bob;
QaAnalyst Joe;
DumbBoss Jane;
Analyst Paco;
};
So looking at this example we can see that the Team class is purely composed of other class objects, which on their own exist elsewhere. So say that each class has it's own header file.
@screw
The name of the magic is Bouml. It can generate c++ and reverse from c++ makes diagrams.
Don't rely on a tool to automate it until you can do it yourself. I have a lot of experience with the engines and those bastards quite often spit out code that is gibberish. If you don't know your UML -> C++ you won't spot the errors.
Composition: The only difference between composition and aggregation is that the part classes that make up the whole, cannot exist outside of the whole. So the death of Team means the death of Bob, Joe, Paco, and thankfully the DumbAss object named Jane. So I guess you could think of it as nested classes?
Spot on exactly what I was looking for. I understand the composition and aggregation now. What about dependency...
To my knowledge a dependency relationship would be along the lines of Passing another object through a method.
For example you could have a tax class that has a tax rate for different states and then you had a store class or something.
In order t calculate the total value of a purchase you would have to pass in the sales tax for a certain state maybe via a pointer or something
or you could have something like this in the header file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include "tax.h"
class store
{
public:
//constructor
etc
Tax get_tax()const;
private:
etc
};
in this case store would have a method called get tax that would get the tax rate for the state that the store is located in and return that tax or return a float
I think im on the right track.
If you had more time return0 i would love it if you could right up some more info for the other relationships. So far though this is some of the most helpful examples on the net. Most of them show you how to make uml from scratch or ideas, but dont show examples of how to write the code or header files of different relationships. I know however this is because there are many different designs etc. But it would be nice to have basic examples. Maybe this can be an idea that someone can add to the c++ tutorial or to this site.