I would maybe add a filter class (TextFilter maybe?) and then add them as an
aggregate objects to your File reading class, I'd maybe have 2 types of
filters.

- Inprocess filter (while you're reading in the files by lines)
- Postprocess filter (after you've read the file in)

So maybe a outline like:

class TextFilter
	def read( text )
		return text
	end
end

class SortTextFilter < TextFilter
	def read( text )
		text = self.sort( text )
	end

	def sort( text )
		#Sort text, maybe ascending by default
		return text
	end
end

fr = FileReader.new( SortTextFilter.new() );
fr.read( "myfile.txt" )
puts fr

Whatcha think?

Zach








-----Original Message-----
From: Florian Weber [mailto:csshsh / structbench.com]
Sent: Wednesday, June 16, 2004 11:11 AM
To: ruby-talk ML
Subject: how to design plugin functionality


hi!

i have a design question. for example i have a class which reads a file
and prints out each line with line numbers. what if now i wanna be able
to plugin some functionality which sorts the file, depending on some
conditions (extension, etc) before its passed on to the line numbering
functionality. the class should be as less tied as possible to the
sorting
functionality as possible..

how would you normally design that in ruby?

would you just overwrite the method which calls the file read method
and passes it to the numbering method?

would you pack an object in between, which would check if the file
has to be sorted, because the conditions are true, read the file and
the return the sorted or unsorted content?

basically im wondering if its considered a good practice to overwrite
methods on the same class or if its kinda hackish.. =)

thanks a lot!

ciao!
florian




---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.705 / Virus Database: 461 - Release Date: 6/12/2004

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.705 / Virus Database: 461 - Release Date: 6/12/2004