UML to code polymorphism

This is a discussion on UML to code polymorphism within the C++ Programming forums, part of the General Programming Boards category; I have this code generated UML. Now, I like him because of you want to check. Did the idea that ...

  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 10: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
    32,852
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    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 09: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, 04:33 PM
  3. Polymorphism
    By Eman in forum C++ Programming
    Replies: 4
    Last Post: 10-31-2010, 07:51 AM
  4. using Polymorphism
    By maro009 in forum C++ Programming
    Replies: 5
    Last Post: 05-23-2005, 01:33 PM
  5. Need help on polymorphism
    By TonyLFL in forum C++ Programming
    Replies: 3
    Last Post: 05-27-2002, 06:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21