From: Carl Jenkins Date: 2010-07-25T10:04:38+09:00 Subject: Re: Design Question David Masover wrote: > On Saturday, July 24, 2010 09:24:28 am Mochi Mochigome wrote: >> Hi guys, >> >> I have a program design question regarding mix-ins. >> >> I currently have 5 modules: > [...] >> and a single class which includes all those modules: >> >> class Client >> include Authentication, User, Issue, Network, Object >> end > > That's not bad in and of itself. It depend show big the modules are. > >> So, is there a more elegant way of doing this? > > Separate objects. > > > class Authentication > end > > class User > end > > class Issue > end > > class Network > end > > class Client > > def initialize > @authentication = Authentication.new > @user = User.new > @issue = Issue.new > @network = Network.new > end > attr_reader :authentication, :user, :issue, :network > end > > > That may or may not work well, depending what you're trying to > implement. For > example, does it make sense to reason about a User or an Issue which > stands > alone, and isn't part of anything else? > > Basically, _is_ a Client a User, or does a Client _have_ a User? > > You may also find that both make sense, sometimes. For example, > DataMapper has > a module that you include (Resource) which extends your class in a > number of > ways to behave like a model object should, but it also ties you into a > number > of separate objects. Some of them obviously shouldn't be part of your > class, > like the repository (represents a database connection). Some of them, > though, > are only about your class -- State, for example -- and of course, you > get a > whole list of properties. > > But what you've got isn't necessarily bad. I hope it is OK that I ask a related question. ( not sure what the etiquette is for this) When programming in Java people use interfaces everywhere in order to program to generic objects. Is this how Modules work as well? If someone includes Modules as the OP mentioned that class just uses those modules it is almost as if we have composition no? So in Ruby is there no such thing as programming to interfaces as there is in Java? -- Posted via http://www.ruby-forum.com/.