Author Topic: Code generation only for classes?  (Read 9099 times)

angel-o-sphere

  • EA User
  • **
  • Posts: 112
  • Karma: +0/-0
    • View Profile
Code generation only for classes?
« on: May 11, 2004, 08:35:55 am »
Hi,

when I try to use code generation on a package containing use cases ... all marked as having language Java ... nothing is generated.

That was only a test. What I really want is defining the language "html" ... or the language "doc" and use the code generation engine to output my use cases.

Unfortunatly that does not work, really sad!!

I wished you could export everything regardless from its classifier type.

angel'o'sphere

Bruno.Cossi

  • EA User
  • **
  • Posts: 803
  • Karma: +0/-0
    • View Profile
Re: Code generation only for classes?
« Reply #1 on: May 11, 2004, 09:49:34 am »
Hi,

how would you translate Use Cases into the code? In object oriented languages at least, there is nothing that would be an equivalent of a Use Case.

Bruno

Bruno.Cossi

  • EA User
  • **
  • Posts: 803
  • Karma: +0/-0
    • View Profile
Re: Code generation only for classes?
« Reply #2 on: May 11, 2004, 09:46:26 pm »
Hi,

I have been thinking about your posting some more, trying to figure out what is it that you are really trying to achieve. It sounds that what you want is not really a code generation (i.e. generation of object structures in the target language) but more of a documentation, am I right? In that case, won't the documentation functionality of EA do?

Bruno

angel-o-sphere

  • EA User
  • **
  • Posts: 112
  • Karma: +0/-0
    • View Profile
Re: Code generation only for classes?
« Reply #3 on: May 14, 2004, 08:23:34 am »
Well,

no the documentation won't do. As it just generates "documentation", which e.g. can not easyly be furhter processed.

I currently help my self with CSV exports, but those don't include relations betwen elements.

What I currently want to do is hand crafted documentation ... but via the code generation feature.

What I later want to do is: CODE GENERATION from a Use Case diagram.

E.g. you can generate a complete FAKE gui for an application just from the use cases and screens ... so what I have to do now is to copy every use case and screen as class into the Logical Model (losing the distinction between screen and UC, needing to use naming conventions).

Then I have to adjust the language of the class to generate PHP or HTML click prototypes or to java to generate a swing prototype.

But I like to do that directly from the UC diagram ... and not from a fake class diagram.

angel'o'sphere

P.S. you can generate a full application skelleton as well just from the use cases ... especially if you can "generate" code from activity diagrams and UCs are linked to activities (the start activity of the associated diagram)
« Last Edit: May 14, 2004, 08:25:52 am by aos »

Bruno.Cossi

  • EA User
  • **
  • Posts: 803
  • Karma: +0/-0
    • View Profile
Re: Code generation only for classes?
« Reply #4 on: May 14, 2004, 11:01:42 am »
Hi,

I can see what you are trying to do, but I have to disagree. You can not generate code or even a GUI sceleton based on Use Cases. If you can, than you likely have Use Cases defined on an inappropriate level.

Bruno

thomaskilian

  • Guest
Re: Code generation only for classes?
« Reply #5 on: May 14, 2004, 12:55:44 pm »
Hi Angelo,
I have to second Brunos statement. I had a recommendation of http://www.usecasemodeling.com by Ian and it's really worth reading. Also I can recommend the ICONIX CD-ROM available here at Sparx. Use Cases seem to be trivial and obvious but they aren't. I always started to functional decomposit problems an thought these were the  Use Cases - completely nonsense  :-[

However, once I really started to learn I'm really a bit wiser then.  ;)
« Last Edit: May 14, 2004, 02:39:47 pm by thomaskilian »

angel-o-sphere

  • EA User
  • **
  • Posts: 112
  • Karma: +0/-0
    • View Profile
Re: Code generation only for classes?
« Reply #6 on: May 17, 2004, 07:32:20 am »
LOL :D,

you probably you lack some phantasy :D!

Example:

First iteration of use case analysis:

UseCase "Withdraw Money"
UseCase "Check Account Balance"


Second iteration of analysis: (you realize that both use cases include the identification/authentification stuff)

UseCase "WithDraw Money"
UseCase "Check Account Balance"
UseCase "Enter Identification Credentials" (in germany a 4 digit PIN after you have inserted the credit card into the ATM)


Third iteration of analysis: (you realize that both use cases have basicly the same flow of events)

UseCase "ATM Transaction" { has extensionpoint performTransaction }
UseCase "Withdraw Money" extends "ATM Transaction"
UseCase "Check Account Balance" extends "ATM Transaction"
UseCase "Enter Identification Credentials"


Fourth  iteration of analysis: ( your robustness and domain analysis (product-family/product-line analysis) shows you to factor out identification because you want to replace the actually used identification/authentification method with retina scanning thechnique next year)

UseCase "Enter Identification Credentials" renamed to Authentification
UseCase Authentification ( via PIN or retina scan or finger print )
UseCase StartTransaction ( by inserting a credit card or starting the ATM via touching the screen or activating a finger print recognizer or retina scanner)
UseCase "ATM Transaction" { has extensionpoint performTransaction } includes Authentification, StartTransaction

UseCase "Withdraw Money" extends "ATM Transaction/{performTransaction}"
UseCase "Check Account Balance" extends "ATM Transaction/{performTransaction}"
UseCase InsertCard generalizes StartTransaction
UseCase AuthenticateWithPin generalizes Authentification

Well, for simple class room example that is allready far to complicated ...

I asume you are familiar with the standard stereotypes <<control>>, <<boundary>> and <<entity>> as well as with actors.

Add actors as appropriated and start creating classes with the appropriated standard stereotypes.

Insert abstract methods for the extension points ... add inheritance(generalization) relations where ever you encounter an extends relation or generalization between use cases. Add aggregation or associaten(as you like) relations between <<control>> classes where the use cases have an includes relation.

Now: mark the two main use cases with a suitable stereotype, e.g. <<dialog>>.

Suppose you have activity diagrams for you UCs ... I would suggest to seperate the activities between <<input>> and <<system>> activities.

Surprisingly you will realize that you can have 2 menu entries in your main menu (or two buttons): "withdraw money" and "check balance". Its not coincident that I suggested to mark the two connected use cases with <<dialog>> ... furthermore you will likely make two dialog classes, one for each use case. You could hav choosen any other stereotype, like <<menu>> as well to indicate that the two use cases can get triggered from the GUI.

Fianally:
By marking the UCs with suitable stereotypes -- or better a tagged value -- you can trigger your generator to create 4 packages: "application", that holds the code for starting the transaction and the main ATM logic, UseCase StartTransaction and UseCase "ATM Transaction", "check balance" and "withdraw money" I would put both into their own package and finally "authentification".

Basic skelletons for the control and boundary classes, the Customer class as actor and their inheritance and aggregation relations and simple configuration classes which serve as constructors for the components (creating the boundaries and dependent controls and wirering them together) ... that all can begenerated from a simple use case diagram.

As a far more in depth read I suggest "Software Reuse" from Ivar Jacobson and Martin Griss, Asdison Wesley - 1997.

Well, the schema above is how I work with use cases. You likely have to find your own way in utilizing them. Nevertheless you will be able to cathegorize your use cases in several ways. E.g. "system" use cases and "external program" use cases where both are triggered by system intern events and run automatically without GUI or user interaction. Then you probably can describe simple use cases like "edit/cut" and "edit/paste" which certainly have simple representation in the GUI as "menu item" in a "menu". Beyond that you can identify use cases which are triggered by a "menu" but lead to a "dialog". The menu entry and dialog caption are likely the same as the name of the use case. Furhter use cases can be cathegorized as "context menu" actions, "drag&drop" actions and "button" clicks leading to ... creation of command objects or to new dialogs or to calls to methods of <<control>> objects.

The question is primarily on what level and granularity you work with UCs and wether you have one or several reference implementations of frameworks or applications (like using MFC or ATL for GUI construction on side or Swing on the other side, both will have totally different ways of GUI generation).

Best regards,
  angel'o'sphere
« Last Edit: May 17, 2004, 07:33:10 am by aos »

angel-o-sphere

  • EA User
  • **
  • Posts: 112
  • Karma: +0/-0
    • View Profile
Re: Code generation only for classes?
« Reply #7 on: May 17, 2004, 08:42:58 am »
This image shows a simple use case diagram, probably afer some 4 to 5 iterations and an deeper understanding about the topic ... not to simple though :D

http://www.oomentor.de/images/simpleUCexample.EMF


And here you see a 1:1 transformation into a class diagram. Read the notes ... its a 1:1 ... not a perfect translation.

http://www.oomentor.de/images/simpleClassExample.EMF

The image shows ho to map UCs and their associations to classes and appropriated associations. You have to do some more "design" to make it really work. The whole point is about automatisation not about perfection.

angel'o'sphere

P.S. sorry, they are made with EA 3.6 and that one refuses to save as gif since some weeks. And my MAC has no EMF -> GIF transcoder :-/

I need some days to transform the images.
« Last Edit: May 17, 2004, 03:40:19 pm by aos »

thomaskilian

  • Guest
Re: Code generation only for classes?
« Reply #8 on: May 17, 2004, 03:27:49 pm »
You can't publish pictures here  :( only a URL for a picture (somewhere on your web server). Too late for a lengthy reply although an interesting topic. I used to have a (quite) similar approach in an earlier project. So I surely can follow your path. However I think this way of interpretation is misleading. Have to think about an answer...

Stephen

  • EA User
  • **
  • Posts: 54
  • Karma: +0/-0
    • View Profile
Re: Code generation only for classes?
« Reply #9 on: May 18, 2004, 06:50:24 am »
Wow - big posts.

Angel'O'Sphere,
Looking in after the dust has settled it appears that what you're after could be possible, but (and its a bit of big but) only if this analyst community could agree a set of naming conventions and practices that intrnsically linked use-cases, the level of detail within them and "screens" (mentioned in your second mail).
It may just be possible within a company with a rigorous quality dept (or a single developer!) and as such is a candidate for your own custom add-in (big job!), however in general we're just not going to all do it the same way - which leads to no automation in the manner you hope for.

I've been travelling in the oppposite direction (as hinted at in my earlier posts) - and I'm trying to strip all but the most basic processes flows out of my use-cases. The UML provides a rich set of descriptive representations. We should make more effort to understand the subtleties of expression that are possible and create suites of models to describe our software. (In so far as they are valuable - don't throw out the XP baby with the bathwater, as we might say in these parts)

I must re-invoke the campaign for simple use-cases!
Try this for a metric - if your client can't understand the jargon, don't put it in a use-case.

If you really want to define everything in one place take a look at the OMG spec. That's how much stuff you'd need as a minimum (and that's not in a single diagram format either...)

[Now what was the difference between a callaboration diagram and a state machine....]

In summary, I agree that its unfortunate that it won't work (your first mail), but I'm not surprised.. :P

thomaskilian

  • Guest
Re: Code generation only for classes?
« Reply #10 on: May 18, 2004, 11:11:58 am »
Angelo,
after thinking a while the following came to my mind: a Use Case should describe something that is of value to an actor. What you impose is that a simple GUI form will equivalate that Use Case. I guess that in more than 90% of all cases this is not true. You will need a set of different forms (if we stay in that terminology) to cover the needs raising from a simple Use Case (CRUD will likely impose a set of 4 different ones). In that project I mentioned above we that convention, that a Use Case equals a CRUD and thus we generated the 4 (we had Tags to control that) CRUD forms. But that was a convention only working in the scope of that special project. From my current standpoint I would use an automation to produce prototype CRUD forms (<<form>> stereotyped classes), linking them to the Use Case in some way and keep the form fields up to date that way.

angel-o-sphere

  • EA User
  • **
  • Posts: 112
  • Karma: +0/-0
    • View Profile
Re: Code generation only for classes?
« Reply #11 on: May 19, 2004, 09:20:37 am »
Yeah I agree with you ... thats why I simply asked if it would not make sense that EA would treat all classifiers equal. So I could use the standard export/generate mechanism for working on the level I like.

I have not the time to use automation ... neither do I know how OLE works nor do I want to fiddle how EA works. (I'm using EA on Virtual PC on a Mac!! I swore a holy oath never to use Windows anymore ..... but EA was to good to drop it, so I have a VPC with one single application ... well, and now I made a SCRUMMaster certification and the SCRUM tools only run good on Excell ... so I have to install Excell on the Virtual PC as well, live is a shit :-/)

You are right in the restrictions you see, however, I don't mind them.

Basicly you need a tailored way of "tagging" use cases for every project ... and a customizeable generator for generating code from that.

Thats what I would do:
- create java source code form a use case. E.G. a set of nested classes for every UC.
- import that code into the logical model and refactor it into the packages I like it ... or probably refactor it in an IDE and import it after that back into EA.

Regarding the CRUD UCs, most CRUD UCs in EA are one one screen and don't use several screens for the several operations(E.g. working with attributes of a class). I wonder what requirements your app had that you could not follow that model.

Don't forget: I tried to make a simple example ... in a longer Use Case I would want to export also activities to Java Source Code ... the activities of the associated Activity Diagram of the Use Case.

So as a summary: the basic idea is to get a generated but likely to simple GUI or app skelleton. Then refactor it according to your needs. thomaskilian, even if my first generation yields classes which are to hughe ... you considered a more fine grained set of dialogs ... I simply can split them in an IDE in a matter of 30 minutes before I reimport them into EA.

Regards,
  angelo
« Last Edit: May 19, 2004, 09:50:24 am by aos »

thomaskilian

  • Guest
Re: Code generation only for classes?
« Reply #12 on: May 19, 2004, 11:09:12 am »
Hi Angelo,
just to complete my previous post. I used RR and its automation interface to do these crude things. Even stranger, we used activity diagrams to feed a workflow engine. I guess, this was really a strange application. In your case I doubt that Sparx will give support for this request. Although it will apply to your requests, it's some kind of contradictionary to the usual Use Case usage.

Btw.: I also would like to work with EA on my iMac. What do I have to spend for that VirtualPC? Does it run under OS X?

angel-o-sphere

  • EA User
  • **
  • Posts: 112
  • Karma: +0/-0
    • View Profile
Re: Code generation only for classes?
« Reply #13 on: May 21, 2004, 01:34:11 am »
Hm,

I wonder why I'm not a full member but a EA newbie, is that post reated?

Well, regarding Sparks, he has nothing to do, just remove the if "clicked package" is in "Logical Model" hierarchie.

From the model point of view it should be the same regardless on which package I click ... just the generate scripts need to get called.

I bought Virtual PC together with a Win 98 installation for it, it was a running out of offer, for about 250 Euros.

It runs on Mac OS X, yes. From 10.2 upwards, probably also on older versions but I have the newest, so I don't know.

What is RR?

Well, a work flow system is predetermined to be described with UML. In that case you easyly can map state diagrams, activity diagrams and use cases to code. In good cases no <<control>> classes need to be modeled, only <<entity>> classes. Most work flow engines/environments use a form of activity or state diagram anyway to model their applications. No big gap from an UML model to such an engine model.

angel'o'sphere

thomaskilian

  • Guest
Re: Code generation only for classes?
« Reply #14 on: May 24, 2004, 08:28:28 am »
<50 = newbie
<100 = junior
>=100 = full

realy doesn't count the worth of posts :-/

RR= Rational Rose (in case you weren't kidding  ;))

Maybe you can ask Sparx for an enhancement in the suggestions forum?