>
> the instance types don't matter as long as they implement .start() and 
> .stop().


Having quite enjoyed the talk, I'm still a bit troubled by this notion. The 
notion that I can trust an object to implement the correct interface simply 
because it has methods whose names I care about is not the same as the 
notion that I can trust an object to implement the correct interface 
because it successfully meets the criteria of implementing that interface. 
Granted, this is quite possibly the closest approximation available in 
JavaScript.

To illustrate in an absurd way: suppose I want to add a Person member to a 
Group list. It's easy enough to assume that an object called "group" 
(because it was passed as an argument) is Array-like because it has a 
push() method, but suppose that object is an instance of Person! 
Person#push is not the same as List#push. Now I've instructed a Person to 
push another Person, which was absolutely not what I meant to do. I doubt 
either of those Persons will be members of my Group.

On Monday, November 25, 2013 7:09:51 PM UTC-8, Danny Eck wrote:
>
> Great talk! I dl'd the mp3 and listened on my reverse commute.
>
> I had gotten so wrapped up in how to create an instance-making service to 
> guarantee all objects in my collection were homogenous (or at least shared 
> a common prototype), that I overlooked the fact that the aggregator 
> *shouldn't* be prescriptive about types. In my contrived chorus/choirboy 
> example, the instance types don't matter as long as they implement .start() 
> and .stop().
>
> myModule.service('chorus', function(){
>    this.members = [];
>    this.addMember = function(){ 
>       // check for .start() and .stop() methods
>    }
>    this.commence = function(){
>       // loop members, member.start()
>    }
>    this.halt = function(){
>       // loop members, member.stop()
>    }});
>
> This seems like the *least* presumptuous. Thanks!
> On Sunday, November 24, 2013 11:03:20 PM UTC-6, Daniel Tabuenca wrote:
>>
>> Factories, and services in angular are singleton by definition. If you 
>> want to create a new instance you could always just do something like:
>>
>> module.factory('myIntanceCreator', function(){
>>       return {
>>            create: function(){
>>                 // create your instance here
>>             }
>>       };
>>
>> });
>>
>> Keep in mind that, contrary to popular belief you don’t need ‘class’ for 
>> true object-oriented-programming. If you get a chance, take a look at this 
>> talk:
>>
>>
>> <http://www.google.com/url?q=http%3A%2F%2Fwww.infoq.com%2Fpresentations%2FIt-Is-Possible-to-Do-OOP-in-Java&sa=D&sntz=1&usg=AFQjCNHH6y8NwMiKFjTjKLq6GLuk7aTgTA>
>> http://www.infoq.com/presentations/It-Is-Possible-to-Do-OOP-in-Java<http://www.google.com/url?q=http%3A%2F%2Fwww.infoq.com%2Fpresentations%2FIt-Is-Possible-to-Do-OOP-in-Java&sa=D&sntz=1&usg=AFQjCNHH6y8NwMiKFjTjKLq6GLuk7aTgTA>
>>
>> One of it’s main points is that Javascript’s closures are actually offer 
>> a much purer form of encapsulation and OOP than even other class-based OOP 
>> languages.
>>
>> In a nutshell, variables and functions defined inside of a closure are 
>> strictly private, while variables or functions that are attached to via 
>> this.myVariable 
>> = value are public. 
>>
>> On Friday, November 22, 2013 7:39:54 PM UTC-8, Danny Eck wrote:
>>
>> Almost wrapped my head around this... Pete's plunkr from 10/14/12 helped 
>>> alot (this might be because the meaning of 'factory' is confusing 
>>> me...) But I'm still struggling with how best to do aggregation with a 
>>> service: Here's a 
>>> Plnkr<http://www.google.com/url?q=http%3A%2F%2Fplnkr.co%2Fedit%2FiKfov5%3Fp%3Dpreview&sa=D&sntz=1&usg=AFQjCNGWEmhhYNR77OIJ4XftcWJWCmbT0g>.
>>>  
>>> I have to use 'new' or $injector.instantiate() somewhere...
>>>
>>> If I want lots of instances of the same class or do some other 
>>> encapsulation, I personally will tend towards OO. How would one accomplish 
>>> this with closures?
>>>
>>

-- 
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/groups/opt_out.

Reply via email to