• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to convert UML diagrams to Java code?  RSS feed

 
Davidd Joness
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to learn the notations of this UML diagram ?

Can you please teach me how to generate Java code from this UML diagram

Also is there any software to do this thing?
uml.png
[Thumbnail for uml.png]
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

What software you using to draw such UML diagram. I believe such software allow you convert to code but not sure.

Actually you ought to understand what your diagram represent and should able to convert to code manually (for small projects)
 
Davidd Joness
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:Welcome to the Ranch

What software you using to draw such UML diagram. I believe such software allow you convert to code but not sure.

Actually you ought to understand what your diagram represent and should able to convert to code manually (for small projects)



I took a screenshot from a website

It is written there that to generate a Java program from the UML diagram

I have not used any software to draw the UMl diagram . I got it from internet .
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not a response to the question per se but to the intent behind the question.

There are those who think that UML is part of a detailed design specification. In fact, a UML diagram is still very much a high-level design spec; it is by nature incomplete and does not include enough detail. Thus, there's no computer program in existence today that can create a full-blown, working Java program from just a UML diagram. Any reasonable expectation in converting a UML diagram to Java would have to be that the generated code is only a skeleton of the program that needs to be written. You need humans to fill out that skeleton with logic and detailed Java code. This is why human programmers are still being paid to do that job. If your expectation is otherwise, then I suggest you go and read Jack Reeves' essays on how Code is Design.

The idea of creating UML, then generating a skeleton program, then filling in that skeleton with detailed logic and code has been around for quite some time. This is the approach that's pushed by proponents of Model-Driven Design and Architecture. I have worked on projects that have tried this approach. Those projects were pretty much abject failures. IMO, the failure is partly because the mindset is backwards. It's the same kind of backwards mindset that thinks that design patterns are the start rather than the end. Design patterns did not just come out of thin air. They came out of a recognition of similarities between several problems and their solutions. First there were specifics, then people generalized ideas into patterns. In fact, there's a rule of thumb that says "You can't have a pattern until you have at least three different examples" or something like that.

The more useful tools, IMO, are the ones that can take a code base, analyze it, and then generate a UML diagram that shows the high-level structure of software components and the relationships that exist between them. The generated UML diagram can give you a good idea of just how complicated and entangled your software design is. Armed with that knowledge, you can go and start refactoring to simplify your design.

Doing it the other way around, the way I think OP is probably thinking of doing it, usually results in complicated and convoluted designs and code that is more likely than not to be incorrect. This is because there is an assumption that the UML diagram is correct when in fact it isn't. Yet, developers feel bound to that initial UML design and they are trapped in it, even when the detailed code that they write eventually—and almost always, inevitably—reveals the unforeseen flaws that were not immediately obvious in the high-level UML design.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This quote is relevant to what I said earlier:
In his book, "Clean Code," Robert Martin wrote:Remember that code is really the language in which we ultimately express the requirements. We may create languages that are closer to the requirements. We may create tools that help us parse and assemble those requirements into formal structures. But we will never eliminate necessary precision—so there will always be code.

And because there will always be code, there will always be a need for programmers who can write it. There may come a time, maybe even in the near future, when those programmers will no longer be human but rather, AI. For now, we'll just have to make do with what we have.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!