amejiarosario / meanshop

🛒 Building an e-commerce application with the MEAN stack
http://meanshop.com
GNU General Public License v2.0
149 stars 104 forks source link

Why you create a product service and call it 'Product', instead of 'ProductService'? #31

Closed dportabella closed 8 years ago

dportabella commented 8 years ago

In products.service.js you create a service named 'Product'. Why? it is a service, not a product. This name is totally misleading. It should be called ProductService.

https://github.com/amejiarosario/meanshop/blob/master/client/app/products/products.service.js

angular.module('meanshopApp')
  .factory('Product', function ($resource, $timeout, Upload, $q) {
amejiarosario commented 8 years ago

It's some kind of convention (see below some references). The name of the file states it is a service: products.service.js. In the code, you can tell if is a service or an instance by the capitalization...

// https://github.com/amejiarosario/meanshop/blob/master/client/app/products/products.controller.js#L8
var products = Product.query();

You can tell the service always starts with uppercase Product while the instance starts with lower case product.

If you take a look at the Angular source code itself you will notice they don't use Service suffix. Neither on popular AngularJS guides like this one.

See:

dportabella commented 8 years ago

I found several cases using the Service suffix in the popular AngularJS you mention:

        var hero = avengerService.find(vm.heroSearch);
        return avengersService.getAvengers()
       return creditService.isOrderTotalOk(vm.total)
    movieService.getMovies().then(function(response) {
    vm.movies = moviesPrepService.movies;
    vm.refresh = sessionDataService.refresh;