{"action":"created","issue":{"url":"https://api.github.com/repos/datathings/greycat/issues/72","repository_url":"https://api.github.com/repos/datathings/greycat","labels_url":"https://api.github.com/repos/datathings/greycat/issues/72/labels{/name}","comments_url":"https://api.github.com/repos/datathings/greycat/issues/72/comments","events_url":"https://api.github.com/repos/datathings/greycat/issues/72/events","html_url":"https://github.com/datathings/greycat/issues/72","id":256527926,"number":72,"title":"Adding implementation details to models","user":{"login":"DataWorm","id":6334555,"avatar_url":"https://avatars0.githubusercontent.com/u/6334555?v=4","gravatar_id":"","url":"https://api.github.com/users/DataWorm","html_url":"https://github.com/DataWorm","followers_url":"https://api.github.com/users/DataWorm/followers","following_url":"https://api.github.com/users/DataWorm/following{/other_user}","gists_url":"https://api.github.com/users/DataWorm/gists{/gist_id}","starred_url":"https://api.github.com/users/DataWorm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DataWorm/subscriptions","organizations_url":"https://api.github.com/users/DataWorm/orgs","repos_url":"https://api.github.com/users/DataWorm/repos","events_url":"https://api.github.com/users/DataWorm/events{/privacy}","received_events_url":"https://api.github.com/users/DataWorm/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-09-10T18:04:55Z","updated_at":"2017-09-11T08:05:16Z","closed_at":null,"author_association":"NONE","body":"Hello,\r\n\r\nI am curious if there is a way to add implementation code like you can do with EMF. At the moment I would like to do something like this for example:\r\n\r\n```\r\ninterface Points {\r\n\tdouble getPoints();\r\n}\r\n\r\nclass SimplePoints implements Points {\r\n\tdouble points;\r\n\r\n\tdouble getPoints() {\r\n\t\treturn points;\r\n\t}\r\n\r\n\tvoid setPoints(double points) {\r\n\t\tthis.points = points;\r\n\t}\r\n}\r\n\r\nclass SummedPoints implements Points {\r\n\tint a,b,c;\r\n\tboolean x;\r\n\r\n\tdouble getPoints() {\r\n\t\treturn (double) (a + b + c + (x ? 1 : 0));\r\n\t}\r\n\r\n\tvoid setAPoints(int points) {\r\n\t\tthis.a = points;\r\n\t}\r\n\t\r\n\t[...]\r\n}\r\n```\r\n\r\nThis already adds some more logic to the model compared to just set and get values but these are still data I need to store, validate and work with. With tools like a Task (can I add further Task implementations myself?) I might achieve calculations like `return (double) (a + b + c + (x ? 1 : 0));`. But I doubt that I could yet define a derived attribute `points` in class `Points` and then define the task implementation in the subclasses `SimplePoints` and `SummedPoints`.\r\n\r\nIn general I am missing some validation mechanism that makes sure a datamodel contains valid data from a logical point of view. Enums could help to define a fixed set of possible values and there might also be a possibility to add annotations to tell that numbers mustn't be negative or similar. Anyway the best solution would be an option to implement validation classes that gets attached to the model and automatically called when a value is going to be changed."},"comment":{"url":"https://api.github.com/repos/datathings/greycat/issues/comments/328450844","html_url":"https://github.com/datathings/greycat/issues/72#issuecomment-328450844","issue_url":"https://api.github.com/repos/datathings/greycat/issues/72","id":328450844,"user":{"login":"dukeboard","id":523965,"avatar_url":"https://avatars0.githubusercontent.com/u/523965?v=4","gravatar_id":"","url":"https://api.github.com/users/dukeboard","html_url":"https://github.com/dukeboard","followers_url":"https://api.github.com/users/dukeboard/followers","following_url":"https://api.github.com/users/dukeboard/following{/other_user}","gists_url":"https://api.github.com/users/dukeboard/gists{/gist_id}","starred_url":"https://api.github.com/users/dukeboard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dukeboard/subscriptions","organizations_url":"https://api.github.com/users/dukeboard/orgs","repos_url":"https://api.github.com/users/dukeboard/repos","events_url":"https://api.github.com/users/dukeboard/events{/privacy}","received_events_url":"https://api.github.com/users/dukeboard/received_events","type":"User","site_admin":false},"created_at":"2017-09-11T08:05:16Z","updated_at":"2017-09-11T08:05:16Z","author_association":"CONTRIBUTOR","body":"Hi, \r\nIndeed we had also the need to add behaviors and computation code directly inside the model. However coming from the EMF world we also remember the main problems of it:\r\n- difficult to update the model when the code is injected into the generated code\r\n- difficult to edit the Java code when it has to be described in the UML/Ecore files (basically no IDE support).\r\nTo try something else and to work around the complexity of Async callback we introduced the notion of a task as a primitive attribute for our models. Task can be directly described in the model when they are simple like: \r\n\r\n```java \r\nclass Test { \r\n   const todo : Task = exp(3+4)\r\n}\r\n```\r\n\r\nBut a task can be potentially way more complex and require some Java code.\r\nWhen it is the case we don't write the code in the GCM file but instead in our Java Code.\r\nto do so we put nothing after the = symbol in the GCM file, meaning that we keep the definition open. Then in the java code you have the ability to do Test.toto = newTask().then{...java code here...}. Finally, when you read the 'attribute' or 'constant' todo, the task is directly executed, there we have exactly the same behavior than a derived attribute.\r\n\r\n"}}
{"actor":{"display_login":"dukeboard"}}