Good use of Adapter pattern?

I'm building my OO skills (about 30 years late) and am learning a little bit about patterns. While they may not be the be all and end all, my current use case might be a good fit for the Adapter. Looking for a little wisdom before I jump in.

I have a module, "data_mine", currently with two methods. "get_random_line_from_file" returns a string from a file, and it uses "array_from_file" to intake a line delimited file of possible data options.

The goal is to change the "get" method so it can take an optional positive integer and return that many items, and for the source of data to be either a line based file, a CSV file, a MongoDB or SQLite datastore, etc.

Is the Adapter pattern a good fit for this refactoring?

Thanks!

Leam

Here's what I have so far. Not sure it's the best looking library ever. :slight_smile:

https://github.com/makhidkarun/ftl_tools/blob/master/lib/ftl_tools/data_mine.rb

Here are the tests. Also lots of room for improvement.

https://github.com/makhidkarun/ftl_tools/blob/master/spec/data_mine_spec.rb

Looking for critique on both.

Thanks!

Leam

ยทยทยท

On 9/2/19 4:17 AM, Andy Jones wrote:

I would have said so, yes. Very much so.

Presumably you will have a model class for each data source, and the adaptor class will instantiate the model class it needs?

-----Original Message-----
From: ruby-talk [mailto:ruby-talk-bounces@ruby-lang.org] On Behalf Of Leam Hall
Sent: 01 September 2019 11:55
To: Ruby users
Subject: Good use of Adapter pattern?

I'm building my OO skills (about 30 years late) and am learning a little
bit about patterns. While they may not be the be all and end all, my
current use case might be a good fit for the Adapter. Looking for a
little wisdom before I jump in.

I have a module, "data_mine", currently with two methods.
"get_random_line_from_file" returns a string from a file, and it uses
"array_from_file" to intake a line delimited file of possible data options.

The goal is to change the "get" method so it can take an optional
positive integer and return that many items, and for the source of data
to be either a line based file, a CSV file, a MongoDB or SQLite
datastore, etc.

Is the Adapter pattern a good fit for this refactoring?

Thanks!

Leam

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Click here to view Company Information and Confidentiality Notice.<http://www.jameshall.co.uk/index.php/small-print/email-disclaimer&gt;

Please note that we have updated our privacy policy in line with new data protection regulations. Please refer to our website to view the ways in which we handle your data.

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;