Thank you for suggestion, Jens

As I understand:
1) each service should extend $scope of controller by adding the 
appropriate methods - there is no need to use JavaScript prototypes at all 
- all methods should be added to $scope
2) it is a 'good style' if one service adds several methods to $scope (I 
mean that there is no need to create a separate service for each similar 
method)

Please correct me if I'm wrong.

On Wednesday, October 1, 2014 5:46:51 PM UTC+3, Jens Melgaard wrote:
>
> Use Composite Reuse Principle instead: Create a Service that does the 
> work, share that service. 
>
> On Wednesday, October 1, 2014 12:07:27 PM UTC+2, Maryan Bahnyuk wrote:
>>
>> Dear Witold
>>
>> On Wednesday, October 1, 2014 10:40:55 AM UTC+3, Witold Szczerba wrote:
>>
>>> From OO perspective, it is a bad idea to use inheritance for code reuse 
>>>
>> IMHO it's much better then just copying the same code from one controller 
>> to another. And inheritance in this case allows not to duplicate code in 
>> two controllers (moreover in 2+ controllers).
>>
>>
>> On Wednesday, October 1, 2014 10:40:55 AM UTC+3, Witold Szczerba wrote:
>>
>>> Also, it is a static linking, so you cannot mock/replace those methods 
>>> in a straightforward way if you need it.
>>>
>> Sorry for possible misunderstanding but I can mock/replace those methods 
>> by changing them on-fly or by making 'hooks'... From another point of view 
>> I do not need this and it's a subject of another discussion :)
>>
>>
>> On Wednesday, October 1, 2014 10:40:55 AM UTC+3, Witold Szczerba wrote:
>>
>>> Sometimes it might be pragmatic to use inheritance, so there is no clear 
>>> "STOP" sign. 
>>>
>> IMHO it's the best way to fix my 'issue' of duplicating code. The main 
>> question is "Does AngularJS have any restrictions regarding such usage or 
>> not?".
>>
>>

-- 
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