I have been really confused when to use factories or services, this SO 
question 
<http://stackoverflow.com/questions/18939709/when-to-use-service-instead-of-factory>
 gives 
a great insight over the difference but I still don't understand over their 
usage. One of the answers gives a very good conclusion of deciding what to 
use when :

In conclusion,

---------------------------------------------------  | Type    | Singleton| 
Instantiable | Configurable|--------------------------------------------------- 
 | Service | Yes      | No           | No          
|---------------------------------------------------  | Factory | Yes      | 
Yes          | No          |--------------------------------------------------- 
 | Provider| Yes      | Yes          | Yes         |       
---------------------------------------------------  


   1. 
   
   Use Service when you need just a simple object such as a Hash, for 
   example {foo;1, bar:2} It’s easy to code, but you cannot instantiate it.
   2. 
   
   Use Factory when you need to instantiate an object, i.e new Customer(), 
   new Comment(), etc.
   3. 
   
   Use Provider when you need to configure it. i.e. test url, QA url, 
   production url.
   

However what was the initial purpose of introducing services, I saw the 
angular code and it seems both of them are same. In fact one is created 
from another doing some debugging I found out that services are created 
from factories and factories are created from providers. We just default 
some values as go down the chain for instance in service you only can 
create an object while in a factory you can create a hash, a value or an 
object but the configuration is default and lastly in provider you can also 
pass the configuration block.
Then what led to creation of services and factories when providers can do 
everything and even more w.r.t. the two ?   

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to