Menu

Class Diagram and Set Up

Máté Kovács

Class Diagram

The set-up of the system:

Static set-up:
  1. Motivation of this representation:
    The static set-up is based on c++ stl containers and classes. The most common stl container is std::vector in this project. I use this kind of representation because rows can be easily converted to vector data structures. You can think of a database (n*m) as a matrix, but instead of using matrices, I use "vector of vectors", in this case a vector of rows and the header row is saved to an other vector.
  2. Items which contain value (ValueElementBase)
    • It is a class, which has virtual methods.
    • The common properties are a flag (empty) which indicates whether is empty or not, if it's not empty, than value has to be set.
    • There're 4 child classes: ValueElementBool, ValueElementInt, ValueElementDouble and ValueElementString. These has different value properties (value), and they can be reached via RowElement struct.
    • These are the elements of a row.
  3. Items which contain header data (HeaderElement)
    • The common properties are name, the column which they represent can be empty or not (canBeEmpty). And there's a type of value indicator (ValueType).
  4. Data of a row (Row)
    • A vector has value-containing-items (row). The row is: 1. item is the 0. element of the vector, and 2. item is the 1. element of the vector, and so on.
    • The vector is a C++ stl vector, so it can be accessed with an iterator.
    • It throws exception when we want to get or delete a non-existing element (it's an enumeration type, Exceptions).
  5. A database table (Table)
    • Every table has it's own name.
    • It has two vectors, one is the vector of the header elements (head), so it describes the row structure of that table. The other vector contains the rows of that table (rows).
    • These vectors are C++ stl vectors, so they can be accessed with an iterator.
    • It has methods for listing, deleting the table. There are other methods which can add new row or header elements to the table.
    • There is a unsigned value (actualPosition), which shows the position in the actually adding row.
    • It throws exceptions when a header already exists, or there's no header with the given name to delete.
  6. Data of a whole database (Database)
    • The common properties are the name of the current database, the tables of that database and an error value, which is a static const value (errorval).
    • Tables are contained in a c++ stl vector, so it can be accessed with an iterator.
    • There are methods which will modify tables by calling table functions. On the other hand the other type of the functions are modifying the whole database, e.g. these can empty or delete the database, or there're methods which has file I/O functions in them and they can load or save the database from/to the exact table and database file.
    • It throws an exception when you want to add a table with the name of an existing table.
  7. Command line and database handling (Handler)
    • This is the interactive part of the database system.
    • The user can type commands to the command line and the system will parse and interpret it. So the user'll get the searched information or can modify the databases and tables in this way.
    • It has methods which manage databases, e.g. delete them or create new ones.
    • One database can be opened at a time (db).
    • It throws an exception, when you want to create a new database with the same name as an other database, or when you want to open a non-existing database.
  8. Connections between classes
    • As I tried to write down in the section above to the classes, these classes are connected to each other.
    • Handler class has one Database, which you can modify via Handler functions.
    • Database class has a vector containing Table pointers. So a Database can have 0 or more Table(s).
    • Table class two vectors of other classes. First one is a HeaderElement vector, this contains the header row of the table. If the table is empty, this vector is empty. If the table isn't empty, than this vector has at least 1 element. Second one is a Row pointer vector, every element of this is a unique row of this table. So this vector can have 0 or more Row(s).
    • Row class has a vector of ValueElementBase pointers. A Row can be empty, than this vector is empty as well. Or it should contain the exact number of elements as you can find in Table's HeaderElement vector. (Every header tag has one value in a specific row. Wheter it can be null or not.)
    • There are 2 enumerations which are used in most of the classes (ValueTypes, OperatorTypes).
    • There is a struct, which is used in ValueElement classes and in Table and Row classes. This contains every type of ValueElement classes' value.
    • This overview of the class diagram (only with class names and relations) is helpful for the section:
      Small Class Diagram
  9. Miscellaneous
    • Exceptions is an enumeration type, it contains all of the exceptions.
    • There are two enumeration types for describing operator types (OperatorTypes) and value types (ValueTypes).
    • To store row elements, we use a vector of ValueElementBase pointers, in real life, those elements will be ValueElement_ types with the correct "template" types (where _ is one of these: Int, Double, Bool, String).
Dynamic set-up
  1. Rows have activities, but the states are not significant to the working of the program.
  2. The Handler'll execute the activities, it'll pass the informations to the database. But the states are not significant here either.
  3. Two methods of the handler has significant state change for the whole system. Opening and closing a database will make this big change. You can or you can't edit a database via the command line or not.
    • On the diagram you can see Hanler::run() is has 2 methods which will change the states.
    • Handler::openDB() opens an existing database and load the data from files. So you can modify these data via the command line. This is the first state (modifiable state).
    • The other state is when you don't have a modifiable state, so you can only open up a database. Handler::closeDB() will lead to this state (the basic state is this one).
    • So important states are on this diagram (only these methods make significant state changes, the others are only modify parts of these states a little bit):
      State Diagram
  4. This diagram shows how the command line will run.
    • The main program has a Handler class variable and via it's Handler::run() method the command line will be shown and it'll run until the user gives the exit command.
      1. Sequence Diagram
  5. The next sequence diagram shows how does a new row adding works.
    • Via a Handler, a Database must be opened (modifiable state), when the user opens up the Table, it'll load data from files (Database::load()), so it can be call addHeaderElement() and addRowElement() and the user as well before the actual row adding command (via command line).
    • So you have an existing Table with header elements and row elements (0 or more).
    • When you give the proper command in Handler::run(), it'll call the addRow() function of the opened Database, and the database'll parse your command. At this point the Database'll call the exact Table::addRowElement() method more times (header elements count times).
      2. Sequence Diagram

Related

Wiki: Diagrams
Wiki: Formats
Wiki: Home

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.