# Object design

**URL:** <https://www.ruby-forum.com/t/object-design/81065>\
**Category:** Ruby\
**Created:** [January 3, 2007, 3:22pm UTC](https://www.ruby-forum.com/t/object-design/81065 "2007-01-03T15:22:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Krekna\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a9adbd/32.png) [@Krekna\_M](https://www.ruby-forum.com/u/Krekna_M)\
**Post date:** [January 3, 2007, 3:22pm UTC](https://www.ruby-forum.com/t/object-design/81065/1 "2007-01-03T15:22:27Z")

</div>

Hi,

Just to make sure, I’d like to know from your as OO programmers if I  
did the ‘object thinking’ right.  
The idea is the following:

1.- I have different development servers (Unix) where the developers  
of various sites have their files to be processed, those files are  
application server archives and web server archives, and maybe other  
files/archives in the future.  
2.- I have a software library server where the software needs to be  
placed for processing via certain tool. Ruby is installed on this  
server.  
3.- When I know the -site name-, I know the source server, source  
directory, destination directory, filename and naming convention, and  
perhaps more necessary info later.  
4.- I have made a list with all this info (I’ve put it in a 2  
dimensional array now) related to a certain site  
eg. [sitename,  
type,src\_server,src\_dir,dest\_dir,appl\_archive,web\_archive,dest\_server]  
5.- I need to find out the version number of the last file from a  
certain site after copying. Because then I can give the new file the  
correct follow-up numer (and some other tweaking)  
6.- The same thing applies to the directory on this software library  
server, they also have a follow up name according to the date  
7.- After this I can call this special tool non-interactively and  
import these archives and check if it all worked out.  
8.- Sometimes in the request they want to have the web archive and the  
application archive to be processed, and sometimes only one of them.

There is a little bit more to this, but those are technicalities which  
are not relevant for the object design question I have, or so I think  
(some checking, file tweaking, comparing, user switching, ssh and scp  
use and so on).

I was thinking at the following objects:

Site object --\> where the methods are at least able to serve all  
the attribute from this list (see point 3 ). This object is called  
with this array (from the list) as an argument

File object --\> where methods are able to give the name, change  
the file name, changing the permissions of the file name

Directory object --\> where methods are able to do the same sort of  
things as with the file name. This object can be a parent of the File  
object maybe.

SiteList object --\> I now have this array just in my front-end code,  
but it could better be in an object? However, it is data, and should I  
put data in an object? It only changes when a site is added, which  
happens two times a year at a maximum.

ThisSpecialTool object --\> Do I need to make an object from this  
special tool which I use non-interactively?

Some sort of Ruby front-end is initializing the the objects and needs  
to be simple, the real code will be in the Site.class.rb,  
File.class.rb and Directory.class.rb

Is this the correct way? I hope you can give me some directions if I  
am doing things correctly.  
How to decide if more objects need to be defined, or some of the  
mentioned objects are not necessary at all?

Many thanks for any help, directions, code examples or whatever!  
Krekna

---

<div class="post-metadata">

**Author:** ![Krekna\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a9adbd/32.png) [@Krekna\_M](https://www.ruby-forum.com/u/Krekna_M)\
**Post date:** [January 3, 2007, 6:05pm UTC](https://www.ruby-forum.com/t/object-design/81065/2 "2007-01-03T18:05:34Z")

</div>

On Jan 3, 2007, at 9:21 AM, Krekna M. wrote:

> 2.- I have a software library server where the software needs to be  
> certain site after copying. Because then I can give the new file the  
> are not relevant for the object design question I have, or so I think  
> the file name, changing the permissions of the file name  
> ThisSpecialTool object --\> Do I need to make an object from this
> 
> Many thanks for any help, directions, code examples or whatever!  
> Krekna

Well you already have a File and Directory that will handle what you  
need in Ruby. You could probably just add some stuff to them. But  
otherwise, it seems reasonable to me.

However, I wonder if you might not need some objects just to marshal  
data around. What I see here are mainly data objects with some  
operations. That might be enough. But if you find yourself having a  
lot of repetition when coding it up, be on the lookout for some sort  
of controller object. Something like ServerConnection comes to mind,  
but it’ll depend on the details of your implementation.  
-Mat

---

<div class="post-metadata">

**Author:** ![Krekna\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a9adbd/32.png) [@Krekna\_M](https://www.ruby-forum.com/u/Krekna_M)\
**Post date:** [January 4, 2007, 12:39am UTC](https://www.ruby-forum.com/t/object-design/81065/3 "2007-01-04T00:39:10Z")

</div>

On 1/3/07, Krekna M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> File object → where methods are able to give the name, change  
> the file name, changing the permissions of the file name
> 
> Directory object → where methods are able to do the same sort of  
> things as with the file name. This object can be a parent of the File  
> object maybe.

Use the ruby classes for this, adding a few things if needed. If you  
need more than a few things, you can probably just subclass them, or  
use Forwardable to avoid duplicating effort.

> SiteList object → I now have this array just in my front-end code,  
> but it could better be in an object? However, it is data, and should I  
> put data in an object? It only changes when a site is added, which  
> happens two times a year at a maximum.

Is your SiteList anything more special than an Array? If it isn’t  
there is nothing wrong with an array. If it is, you can preserve  
much of your functionality by implementing a meaningful SiteList#each  
and including Enumerable

> ThisSpecialTool object → Do I need to make an object from this  
> special tool which I use non-interactively?

Not necessary, but good for organization, future use, and of course,  
unit tests.

> Some sort of Ruby front-end is initializing the the objects and needs  
> to be simple, the real code will be in the Site.class.rb,  
> File.class.rb and Directory.class.rb

site.rb, file.rb, directory.rb

but there is no need for file.rb / diretory.rb unless the ruby classes  
are too far from the mark.
