Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Scala objects? Are they evil?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
matroska  
View profile  
 More options Oct 19, 4:58 pm
From: matroska <tobia.loschi...@gmail.com>
Date: Mon, 19 Oct 2009 13:58:46 -0700 (PDT)
Local: Mon, Oct 19 2009 4:58 pm
Subject: Scala objects? Are they evil?
Hi all,

I was wondering which is the right approach to follow when you want to
test classes that uses singleton objects. Should we avoid the use of
singleton "object" in our scala programs? For example, if we think to
have DAO objects, they should be singleton right? But at the same time
we need to test the classes that use them in some way. The problem is
that with the syntax we use in scala we would call the singleton dao
with Dao.getAllStudents() within the classes that use the dao and I
personally cannot understand how to mock them. Should we avoid
objects? How could we test classes that use singleton?

Thanks in advance
Tobia Loschiavo


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dick Wall  
View profile  
 More options Oct 19, 5:11 pm
From: Dick Wall <dickw...@gmail.com>
Date: Mon, 19 Oct 2009 14:11:10 -0700
Local: Mon, Oct 19 2009 5:11 pm
Subject: Re: Scala objects? Are they evil?
Scala gives you all sorts of possibilities for testing Singletons, but
if you control the code-base the best bet is to avoid traditional Gang
of Four singletons entirely. I would recommend looking at dependency
injection as an alternative - something like Guice or the cake pattern
demoed by Martin Odersky (personally I use Guice because of
familiarity and also I find it slightly more powerful). Using DI will
let you have an easy to test codebase and still control everything
about the unit testing of the classes, and you can still effectively
have singletons (the @Singleton annotation in Guice) without paying
the cost of that hard-wiring.

Scala objects are useful for a bunch of other things too though, for
example companion objects, case objects, etc. so I don't believe a
general rule about avoiding them is a good idea.

--
Dick Wall
Email: d...@bldc.org    Gmail: dickw...@gmail.com     Skype: dickwall
  AIM: QuaintRcky
Co-Host of the Java Posse: http://javaposse.com    Blog:
http://dickwallsblog.blogspot.com

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kevin Wright  
View profile  
 More options Oct 19, 5:18 pm
From: Kevin Wright <kev.lee.wri...@googlemail.com>
Date: Mon, 19 Oct 2009 22:18:50 +0100
Local: Mon, Oct 19 2009 5:18 pm
Subject: Re: Scala objects? Are they evil?
singletons can inherit from other classes and from traits, so one
possibility is to write your tests against one of these.

It's also not right to just think of a singleton as global state,
classes can have inner singletons too - in which case you'll actually
end up with one singleton per instance of that class :)


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tobia Loschiavo  
View profile  
 More options Oct 20, 8:39 am
From: Tobia Loschiavo <tobia.loschi...@gmail.com>
Date: Tue, 20 Oct 2009 05:39:27 -0700 (PDT)
Local: Tues, Oct 20 2009 8:39 am
Subject: Re: Scala objects? Are they evil?
Thank you for your answers.
I have no experience on Guice but I think it should be simple. Anyway
I would like to use Guice without using @Singleton on classes but
keeping using @Inject onto scala objects. Is it possible? Is there any
example? I should also avoid setter injection (that would involve var
usage) and use constructor injection instead. Is this right?

Thank you again.
Tobia Loschiavo

On Oct 19, 11:18 pm, Kevin Wright <kev.lee.wri...@googlemail.com>
wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google