Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

in my current project have:

module Stats

  class Site
    ...
  end

  class Product
    def initialize(product_id)
      @product_id = product_id
    end
  end

  class Profile
    ...
  end

end

now in my Product class have methods to get/set product views(day, week, month) and methods to get/set product sales(day, week, months)

is better to namespace like Stats::Product::Views and Stats::Product::Sales or simply prefix methods like sale_add and view_add?

example calls with namespace:

Stats::Product::Sales.add(product_id) # increment sales counter 
Stats::Product::Sales.today(product_id) # get n. today sales  
Stats::Product::Sales.week(product_id) # get n. week sales  

Stats::Product::Views.add(product_id) #increment product page view counter
Stats::Product::Views.today(product_id) #get n. today product page views
Stats::Product::Views.week(product_id) #get n. week product page views

example with current structure:

Stats::Product(product_id).sale_add # increment sales counter 
Stats::Product(product_id).sales_today  # get n. today sales 
Stats::Product(product_id).sales_week # get n. week sales 

Stats::Product(product_id).view_add #increment product page view counter
Stats::Product(product_id).views_today #get n. today product page views
Stats::Product(product_id).views_week #get n. week product page views

Now, what you think is more elegant solution? and why?

share|improve this question

migrated from codereview.stackexchange.com Jan 23 at 19:53

This question came from our site for peer programmer code reviews.

    
sale_add, view_add seems more clarified, anyway what have you to do with ::Views/Sales? –  Малъ Скрылевъ Jan 24 at 4:49
    
"simply prefix methods like sale_add and view_add?". I don't understand what you mean by this. Can you please clarify? –  Wayne Conrad Jan 24 at 8:37
    
Updated question with examples –  byterussian Jan 24 at 11:27
    
The first Stats::Product::Sales.add(product_id) variant is more clear. –  Малъ Скрылевъ Jan 29 at 3:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.