Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I am trying to create a UML Class Diagram Editor and Generator of Class Files in (PHP but open to support for other language) based on the Diagram as a school project and I am having a difficulty on designing my classes to fit with the project.
 
for example, if I will create a class UMLEntity(these are the items that can be added diagram) base class which will be extended by UMLClass and UMLInterface that both have UMLMember (UMLProperty, UMLMethod). The problem is UMLEntity and UMLMember both have modifiers (public, protected, private, static, abstract, final etc) but limited depending on each type (ex. interface can only have public members and cannot be static, interface cannot be static). so maybe I should automatically set those members as public, but how?
 
Can anyone help me out what is the better way for this scenario.
 
Please help me out.
 
Thank you.
Posted 9-Dec-12 4:09am
Daskul555
Edited 9-Dec-12 13:56pm
v2
Comments
Sergey Alexandrovich Kryukov at 9-Dec-12 11:52am
   
Actually, there will be many problems of OOP design in this project. As to the one you are trying to describe, it's not just clear. What does it mean: "limited depending on each type"? How and why would you like to have them "unlimited"? Also, you need to tag the platform and the language. Please use "Improve question" above.
--SA
Daskul at 9-Dec-12 20:04pm
   
I apologize, Thank you for your response. By saying limited I mean, for example not all members of an UMLEntity can be static, private like members of an UMLInterface. and you cant use all those modifiers at the same time.
 
I hope this answers your question
Sergey Alexandrovich Kryukov at 9-Dec-12 20:20pm
   
So what? Do you want modifiers to change from base class to derived classes? This is impossible (unfortunately). But what's the idea? how could it help you to build the file system and the tools?
--SA
Daskul at 9-Dec-12 20:32pm
   
What I am trying to say is, should I create an interface like IAccessModifier which will have properties like (IsStatic, IsAbstract etc) and will be implemented by Entities and Members? because I think i cant achieve it by inheritance, can it be(?).
 
My idea is one Item on the diagram will be an instance of UMLEntity (UMLEntity or UMLInterface) then when the user wants to save it (want to come back to it the next day) the data will be stored in an XML, then it will be use to load and instatiate all the objects (UMLEntity) again and create the diagram.
 
I am using WPF.
Sergey Alexandrovich Kryukov at 9-Dec-12 21:06pm
   
For persistence, better use Data Contract. This way, persistence will be totally separated from semantic (agnostic). Data Contract is based on Reflection and can work with any members you include, even private.
--SA
Daskul at 9-Dec-12 21:16pm
   
Thank you sir I will check that out. I guess it is use only for read/write from lets say xml to .Net objects and vice-versa. and creating a inheritance tree is still neccessary like my previous concern?
Daskul at 9-Dec-12 21:21pm
   
I forgot to tell you sir that part of my project is to create a parser for XML and UML Class diagram for saving and loading the diagram. so i think i cant use data contract. I really apologize.
Sergey Alexandrovich Kryukov at 9-Dec-12 22:52pm
   
With Data Contract, parser is already done for you.
--SA
Daskul at 9-Dec-12 23:05pm
   
Yes sir that's what im trying to say, it is already done. The purpose of my project is to CREATE a parser that will save and load .Net objects (UMLENtity) from XML (vice-versa). What else should i do if it is provided by "Data Contract". Now going back to my original question, Thats why i am focusing my questions on how to Structure my CLASSES to fit on this UML Editor project for easy PARSING from UMLEntity(s) to XML files vice-versa.
Sergey Alexandrovich Kryukov at 9-Dec-12 23:11pm
   
Why? Sometime you need it, but why, in your case?
Whatever. You need to isolate persistence from your classes. In other word, good persistence should save and restore any object graph without prior knowledge on the classes involved. If you doing something less powerful than that, you are just wasting your time.
--SA
Daskul at 10-Dec-12 0:37am
   
If you'll be the one to design it, what is your approach regarding this project? Can you please share your idea.
 
Thank you
Sergey Alexandrovich Kryukov at 10-Dec-12 1:13am
   
UML diagramming or persistence?
--SA
Daskul at 10-Dec-12 1:33am
   
it would be better sir if you provide both. ^_^
why you came up with that, what is good about that approach. what are the drawbacks on other approach.
 
those questions are also the reason sir that's why i am looking for a mentor. its rare to see answers like that in the internet.
 
thanks a lot sir for being patient responding to my post ^_^
 
Sergey Alexandrovich Kryukov at 10-Dec-12 9:09am
   
Not easy to answer of persistence. I created two such technologies, working at another one. Are you sure you don't want to use existing Data Contract. I can give you some directions, but not sure you will be able to follow them... And I already have some answers on diagramming.
--SA
Daskul at 10-Dec-12 10:00am
   
I dont know sir, please help me to decide.
The purpose of my study is to use existing parsing algorithm to read/write xml for loading and saving of UML Diagram respectively. The UML Tool will also generate PHP Files based on the diagram. So I am afraid I cant use the Data COntract or other built in libraries because it will break the purpose of the study.
 
I also checked out Reflection, but i dont know if it will be a good choice.
 
So what I am planning to do is create a Inheritance Tree(dont know what the actual term is) which will mimic the data that are inside a Class or Interface. like this :
 
UMLEntity
-Properties
* Name
* List of fields (maybe type of UMLEntityProperty )
* list of methods (maybe type of UMLEntityMethod )
 
UMLClass extends UMLEntity
UMLInterface extends UMLEntity
 
so one object on the UML Diagram will be equivalent to an instance of type UMLEntity (UMLClass/UMLInterface)
 
By the way I am going to use C# 4.0, WPF + XAML. So i hope design of my classes wont get me into trouble in data binding.
 
or is there a better way than this?
Sergey Alexandrovich Kryukov at 10-Dec-12 16:26pm
   
The idea of semantic parsing is wrong! What is the "existing parsing algorithm"? If this is a general XML parsing (like XmlReader), its fine. The parsing should be agnostic to application, that's it. If a parser needs to know anything about UMLEntity, stop it all and think at what you are doing. Persistence should be totally semantic-agnostic...
 
I advise use of WPF as well (why XAML though? only for general layout design). You should persist the UML model itself, plus its geometry. And you should have persistence agnostic to that model and anything related to application. If you are not using MS Data Contract, you need to create your own Data Contract technology. It should use Reflection. (And performance needs also to use System.Reflection.Emit). And no way you should persist XAML...
 
--SA
Daskul at 10-Dec-12 20:44pm
   
I agree that using data contract is more convenient, but what I must do is "manually" traverse the UML Diagram objects, and get all the UMLEntity data and then save them to XML, I also need to manually load them by using XMLReader, and instantiate UMLEntity(s) based on the data fetched on the XML.
 
Base on what I read about Data Contract it automatically save/load data on XML.
 
I will use XAML for data binding, styles, triggers for user experience. Do I need to use geometry? where can I use it? I thought the only thing I need is the Polyline.
 
On Pattern I will use MVVM, Can you help me sir design my Domain Models for the UML?
 
The study will be accepted only if I will traverse data back and forth from XML and Memory manually.
 
All your solutions are well accepted, but I need different approach. And that is manually traverse the data.
Sergey Alexandrovich Kryukov at 10-Dec-12 23:39pm
   
It's not just convenience; this is proper architecture.
 
Now, the geometry is a kind of a problem in architecture, because, ideally, UML structure should be abstracted from geometrical properties of the nodes. This is hard to do, so, in practice people store geometry along with UML semantics. This is not too big sacrifice of architectural purity.
 
As an isolation device, I would advice to loose bound geometry from UML semantic classes. You can make geometry objects separate objects, with its own unrelated hierarchy. Each UML node should merely reference an instance of geometry object. I would also advise to store geometry model in abstract terms, so it should not be related to platform graphics, XAML or anything like that. It should be translated to graphics specific to the platform in some UI/presentation level. A not more works, but the result will be more manageable, and, most importantly, more portable. Those UI libraries and frameworks change way too often to put the project at risk.
 
In order to properly design loose coupling between UML model and its geometry, I would advise to read on dependency injection.
 
MVVM? Why not? Helping to design MVVM? Too much communication and work on my side, I'm afraid; besides, I'm starting to loose interest to this work... Shall I explain why?
 
I've read this:
"The study will be accepted only if I will traverse data back and forth from XML and Memory manually."
 
I would look for better way of learning programming. Can you argue over those requirements? I would never comply. I cannot imagine doing something which I think is wrong...
 
--SA
Daskul at 11-Dec-12 20:18pm
   
But can you still help me sir on the UML Model part? Can you show me the class hierarchy and example on how to use it?
 
thank you very much sir
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You need to look at Data Contract. Please see:
http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].
 
Please see my past answer where I explain it:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating property files...[^].
 
—SA
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Please see my comments on persistence. If should be either Data Contract or something like that. It should be agnostic to UML. As soon as your persistence start depending on UML definitions or anything of application field, consider all your development dead. And it should be no XAML, because this way you lock yourself in dealing with geometry first. You need model first approach.
 
As to diagramming, please also see my past anwers:
^],
Vector graphics software like CorelDraw or Inkscape in C# or VB.NET[^].
 
[EDIT]
 
Daskul wrote:
The study will be accepted only if I will traverse data back and forth from XML and Memory manually.
Let me comment on this.
 
I cannot believe you understand what's required of you properly. I think the matter of this is that you just need to do XML-related development by yourself, at the level of XmlWriter/XmlReader or something like that. Can you see the difference? Essentially, I don't think anyone wants you to produce that total manual trash. This is natural: study projects are normally done to benefit you with the possibilities of sharpening many useful skills. Working with XML on this level is a very useful productive and educational activity which can help you to become a really capable engineer.
 
You need to do some right thing on good reasonable level. Nobody wants monkey job from you. The conclusion? You need to do your own, maybe highly simplified (more exactly, limited in functionality) Data Contract persistence. You own. You just need to learn Reflection, reading attributes, properties, instantiation of types, etc. Based on that, you define type-agnostic storage and loading — saving and restoring of some object graph.
 
You can skip on System.Reflection.Emit. It is needed only for performance reason and compromises the maintenance of the serializer. Without it, it just repeats Reflection operations over and over instead of dynamic generation of serialization code. This is not too bad. In near past, when Microsoft Data Contract was not yet available and when I did not yet had all my knowledge of CIL and emitting of CIL code, I did such work. Nothing terrible.
 
—SA
  Permalink  
v2
Comments
Daskul at 12-Dec-12 20:16pm
   
reviewing your previous comments sir, i guess youre right that its better or should i say the right thing, to just build my own simple data contract. i can still use parsing then using relfection right?
Sergey Alexandrovich Kryukov at 12-Dec-12 20:20pm
   
Yes you can and I think you should. Reflection is a valuable feature available only on new platforms, it would be a sin to ignore it.
Did you see my new post with class hierarchy? Will you accept it, too?
--SA
Daskul at 12-Dec-12 20:23pm
   
thanks a lot. as a beginner i find it overwhelming :)
but ill just review it till i get the concept of the hierarchy.
Sergey Alexandrovich Kryukov at 12-Dec-12 20:27pm
   
Well, this is natural. I would expect you could find it insufficient at the same time. :-)
If you are a beginner, it's may be a time to begin. :-) The problem is not simple at all, for a beginner. Anyway, your further questions are welcome, no matter if you accept the answer(s) or not.
--SA
Daskul at 12-Dec-12 20:45pm
   
ALL answers, comments, questions are VERY much accepted :-)
can you some reference about OOP, Interface Programming and other important concepts of software engineering? cant find ebooks on some of those.
Sergey Alexandrovich Kryukov at 12-Dec-12 22:49pm
   
Well, I also meant formally, Solution 3.
As to literature... hard to say something certain, in one book. Everything I was had some problems. Perhaps you have to ask a separate fresh question.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

OK, I'll show some very rough sketch of UML hierarchy. Very preliminary, pseudo-code, and only for Class Diagram and top level. Perhaps you well see that you might under-estimate the task.
 
Let's start with abstract top level of hierarchy:
    abstract class Element {
        // Name: string;
        // UniqueId;
        // ...
    }
    abstract class NormativeElement : Element { }
    abstract class InformativeElement : Element { }
    class Comment : InformativeElement {
        // Content: string;
    }
 
Let's classify NormativeElements into three entities:
    abstract class Type : NormativeElement {
        // Namespace
    }
    abstract class Relationship : NormativeElement {
        // Stereotype: Stereotype;
        // StartingEnd: RelationshipEnd;
        // FinishingEnd: RelationshipEnd;
    }
    class Stereotype : NormativeElement { }
 
Now, model the types and generic type. Pay attention: we shall not classify them into types and generic types, for some good reasons:
    class SimpleType : Type { }
    class EnumerationMember : Element { }
    class EnumerationType : SimpleType {
        // EnumerationMembers: Collection of EnumerationMember
    }
    class ComplexType {
        // Operations: Collection of Operation;
        // IsInternal : Boolean;
        // AccessLevel: AccessLevel;
    }
 
    class Class {
        // in UML, there is no distiction between class and struct
        // we also won't introduce generic type as a separate entity: it will be modelled 
        // as a class with some generic parameters
        //
        // GenericParameters: Collection of GenericParameters
        // Attributes: Collection of Attribute
    }
 
    class GenericParameter {
        // GenericParameterConstraints : Collection of ComplexType
    }
    
    class Interface : ComplexType { }
 
    class Member : Element { }
    class Operation : Member {
        // returnType: Type;
        // parameters: Collection of ParemeterDescriptor;
        // AccessLevel: AccessLevel;
    }
    class Attribute : Member {
        // Type: Type;
    }
 
    enum AccessLevel { IsPrivate, IsProtected, IsPublic, } // "internal" could be a separate member
    enum ParameterPassingMethod { In, Out, InOut }
 
    class ParemeterDescriptor {
        // Type: Type;
        // PassingMethod: ParameterPassingMethod;
        // IsConstant: Boolean;
        // AccessLevel: AccessLevel;
    }
 
Now, adding the relationships:
    class Cardinality {
        // Min: uint;
        // MaxLength: uint; // Max = Min + MaxLengh, to avoid Max < Min, etc.
        // IsUnconstrant: use MaxLength or not
    }
 
    class RelationshipEnd {
        // Cardinality: Cardinality;
    }
 
    abstract class DependencyBase : Relationship { }
    class Dependency : DependencyBase { }
    class Permission : DependencyBase { }
    class Usage : DependencyBase { }
 
    class Generalization : Relationship { }
    class Realization : Relationship { }
 
    class Composition : Relationship { }
    class UniComposition : Relationship { }
    class Aggregation : Relationship { }
    class UniAggregation : Relationship { }
 
Finally, the top of object hierarhy:
    class Model : Element {
        // Elements: Collection of Element;
        // Diagrams: Collection of Diagram;
    }    
    abstract class Diagram : Element { }
    class ClassDiagram : Diagram {
        // Elements: Collection of elements, diagram view
        // additional refernces to same elements as in Model
    }
    
    // you will need to elaborate all other types of diagrams:
    class UseCaseDiagram : Diagram { /* ... */ }
    class UseSequenceDiagram : Diagram { /* ... */ }
    class CollaborationDiagram : Diagram { /* ... */ }
    class StateChartDiagram : Diagram { /* ... */ }
    class ActivityDiagram : Diagram { /* ... */ }
    class DeploymentDiagram : Diagram { /* ... */ }
    // did I forget anything? :-)
 
You will also need to develop separate geometry classes and bind them with model classes as loosely as possible. You can face the problem of parallel hierarchies which can potentially compromise maintenance. I devoted a part of my CodeProject article to this problem. Please see: Dynamic Method Dispatcher[^].
 
To understand this chapter, you will need to read the whole article, which can be useful by itself.
 
What else? Well, you should understand the sense of what you are doing and why. This is a meta-model, a (meta)3-architecture expressed in the form of (meta)2 model. Generally, if the set of some classes present some model, then the modeling of the notion of the class itself and related notions is a meta-model of a class of different models, a meta-meta-model…
 
—SA
  Permalink  
Comments
Daskul at 14-Dec-12 1:12am
   
Sir can i ask how to implement or more detailed approach on the Type class? how can i use it? what should be the content of the class? who extends it? who and how will i interact with the object?
 
as well as the relationship. cant quite figure out how to implement it. can you make it crystal clear for me sir?
 
thanks a lot
Sergey Alexandrovich Kryukov at 14-Dec-12 13:32pm
   
There is almost nothing in this class. I can see only the Namespace, at the moment. It should not have any public functionality. It's major role is to be the abstract base for its descendants. Who extends is? -- see the rest of the classes.
 
I forgot to write a disclaimer to my sketch: use it on your own risk. :-)
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 6,745
1 OriginalGriff 6,696
2 CPallini 5,315
3 George Jonsson 3,599
4 Gihan Liyanage 2,650


Advertise | Privacy | Mobile
Web04 | 2.8.140922.1 | Last Updated 12 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100