Thread: UML to code polymorphism

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    1

    UML to code polymorphism

    I have this code generated UML. Now, I like him because of you want to check. Did the idea that he does not quite right ... Because this is my first time I'm going with polymorphism.

    UML: Attachment 12640

    Code:
    #include <cstdlib>
    #include <iostream>
    #include <string>
    
    
    using namespace std;
    
    
    class DrawObject{}
    
    
    class Rectangle : public DrawObject{
          private: 
                   Point leftBottom;
          private: 
                   int length, width;
          public:
                 Rectangle( int length, int width)
                 : length(length), width(width){
                                   };
                                   void draw() const;
          }
          
    class Triangle : public DrawObject{
          private: 
                   Point pA, pB, pC;
          public:
                {
                 };
                                   void draw() const;
          }
          
    class Circle : public DrawObject{
          private: 
                   Point center;
          private:
                  int radius;
          public:
                 Circle( int radius)
                 : radius(radius){
                                   };
                                   void draw() const;  
          }
    
    
    class Oval : public DrawObject{
          private: 
                   Point center;
          private:
                  int xRadius, yRadius;
          public:
                {
                 };
                                   void draw() const;
          }
    
    
    typedef struct {
      int xPos;
      int yPos;
    } Point;
    
    
    
    
    
    
    
    
    int main(int argc, char *argv[])
    {
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    Last edited by Chriskras; 03-26-2013 at 09:35 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Perhaps you should try again, because there is no attachment.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Inheritance is represented with generalization links in UML (Open arrows). Realization links (Closed triangle arrows) are used to represent inheritance from an interface. Polymorphism can be represented using these. If the code generator is fairly decent it will use inheritance when your UML uses it and if it is an interface it will be a pure abstract class. Most UML tools allow you to specify the inheritance type in the properties of the object and this should be reflected in the generated code.

    On a side note code generated from UML tools is usually awful and I would not recommend it even as a starting point. I have never had good luck with it in Enterprise Architect or Visio. I do not have experience with Rational Rose so I cannot comment on it.
    Last edited by VirtualAce; 03-28-2013 at 08:59 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Polymorphism
    By tinu73 in forum C++ Programming
    Replies: 5
    Last Post: 11-06-2012, 08:50 AM
  2. Polymorphism in C++
    By jakebird451 in forum C++ Programming
    Replies: 9
    Last Post: 10-25-2011, 03:33 PM
  3. Polymorphism
    By Eman in forum C++ Programming
    Replies: 4
    Last Post: 10-31-2010, 06:51 AM
  4. using Polymorphism
    By maro009 in forum C++ Programming
    Replies: 5
    Last Post: 05-23-2005, 12:33 PM
  5. Need help on polymorphism
    By TonyLFL in forum C++ Programming
    Replies: 3
    Last Post: 05-27-2002, 05:50 PM