meisyal / staruml-ruby

A Ruby extension for StarUML.
https://staruml.io/extensions
MIT License
26 stars 1 forks source link

interface - attribute not generated #11

Open huseyin39 opened 5 years ago

huseyin39 commented 5 years ago

Hello, When creating an interface on StarUML and giving an attribute, the code generation doesn't create that attribute (would be CONST of ruby). Thanks!

meisyal commented 5 years ago

Hi @huseyin39,

Taking from Java programming language, an interface is a basically blueprint of methods that the class who implements the interface. In other words, an interface only contains several methods. It doesn't contain attribute or instance variables.

This extension converts an interface to a Ruby module. You can look the example here.

So, if this doesn't work with your case. Could you share your class diagram or example of an interface with attributes? What should generated Ruby code be?

huseyin39 commented 5 years ago

In Ruby module, you can have variable. It is one of the purpose of Ruby's module with methods.

For example, I create an interface on StarUML 'Interface' and give it a attribute 'var' and with a value 'value'. So I expect the extension to create a module named 'Interface' with a variable named 'var' with 'value' as value.

It generates module Interface end

I would expect it to generate:

module Interface var = value end

meisyal commented 5 years ago

Could you share resources of a Ruby module with attributes?

As I understand it, an interface contains only several methods that to be implemented by a class who implements it. It can't contain attributes. If you want to add attributes, you should create an abstract class instead of interface. By the way, I don't know how to implement abstract class on Ruby.

Here are some resources about interface:

  1. What Is an Interface?
  2. Abstract Classes & Interfaces
  3. What is the difference between an interface and abstract class?
huseyin39 commented 5 years ago

I am not talking about Java interface but about Ruby module. There is not Ruby's module in StarUML, so we can consider implementing module from StarUML's interface.

See below the first line: "A Module is a collection of methods and constants." Ruby Module

meisyal commented 5 years ago

I see. You are talking about constants in Ruby module. Yes, this extension doesn't generate that.