{"action":"created","issue":{"url":"https://api.github.com/repos/daokoder/dao/issues/352","labels_url":"https://api.github.com/repos/daokoder/dao/issues/352/labels{/name}","comments_url":"https://api.github.com/repos/daokoder/dao/issues/352/comments","events_url":"https://api.github.com/repos/daokoder/dao/issues/352/events","html_url":"https://github.com/daokoder/dao/issues/352","id":54991107,"number":352,"title":"Public constructors in modules","user":{"login":"Night-walker","id":5074460,"avatar_url":"https://avatars.githubusercontent.com/u/5074460?v=3","gravatar_id":"","url":"https://api.github.com/users/Night-walker","html_url":"https://github.com/Night-walker","followers_url":"https://api.github.com/users/Night-walker/followers","following_url":"https://api.github.com/users/Night-walker/following{/other_user}","gists_url":"https://api.github.com/users/Night-walker/gists{/gist_id}","starred_url":"https://api.github.com/users/Night-walker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Night-walker/subscriptions","organizations_url":"https://api.github.com/users/Night-walker/orgs","repos_url":"https://api.github.com/users/Night-walker/repos","events_url":"https://api.github.com/users/Night-walker/events{/privacy}","received_events_url":"https://api.github.com/users/Night-walker/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-01-21T08:35:43Z","updated_at":"2015-01-21T11:55:13Z","closed_at":null,"body":"Once again, I'm facing the very same design pattern -- there are classes which are not supposed to be directly instantiated by the user. A simplest example is `os::Path` I rolled out recently.\r\n\r\nIt is not sufficient to just comment it like \"don't you dare use this constructor!!!\"; and it is quite ridiculous when a monumental module architecture may crumble miserably if you mistakenly use what you're not supposed to.\r\n\r\nI think there is need for ability to define constructors which appear public in the scope of a module, but become private/protected from outside it. In the simplest case, any `protected` constructor, for instance, may be deemed `public` within the current source file or files which are included by this file.\r\n\r\nWhile this does not strictly seal off such constructor from the user, the chance of misuse is lower because sub-classing or mixing a class is not an action to be performed spontaneously."},"comment":{"url":"https://api.github.com/repos/daokoder/dao/issues/comments/70824971","html_url":"https://github.com/daokoder/dao/issues/352#issuecomment-70824971","issue_url":"https://api.github.com/repos/daokoder/dao/issues/352","id":70824971,"user":{"login":"daokoder","id":1860002,"avatar_url":"https://avatars.githubusercontent.com/u/1860002?v=3","gravatar_id":"","url":"https://api.github.com/users/daokoder","html_url":"https://github.com/daokoder","followers_url":"https://api.github.com/users/daokoder/followers","following_url":"https://api.github.com/users/daokoder/following{/other_user}","gists_url":"https://api.github.com/users/daokoder/gists{/gist_id}","starred_url":"https://api.github.com/users/daokoder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daokoder/subscriptions","organizations_url":"https://api.github.com/users/daokoder/orgs","repos_url":"https://api.github.com/users/daokoder/repos","events_url":"https://api.github.com/users/daokoder/events{/privacy}","received_events_url":"https://api.github.com/users/daokoder/received_events","type":"User","site_admin":false},"created_at":"2015-01-21T11:55:13Z","updated_at":"2015-01-21T11:55:13Z","body":"> And how to use it then?\r\n\r\nI just come up with one solution:\r\n~~~ruby\r\nnamespace NameSpace{ PublicClass }\r\n\r\nclass PrivateClass\r\n{\r\n    routine PrivateClass( x: int ){  # public constructor;\r\n    }   \r\n    routine PrivateClass( x: PrivateClass ){  # private constructor;\r\n    }   \r\n}\r\n\r\ninterface PublicInterface\r\n{\r\n    routine PublicInterface( x: int );\r\n}\r\n\r\nconst PublicClass: PublicInterface = PrivateClass\r\n~~~\r\n\r\nNote: it is not working now, but I intend to fix it."}}