odpogn
odpogn

Reputation: 11

What is Business Logic?

Can the term business logic be used to describe:

account roles (admin, end-user, unregistered-user, moderator) that control what data is available to the end user?

If not, can someone give offer a term to describe the above situation, and correct me in exactly what business logic means? How does it differ from business rules? examples? Would you put the Business Logic Layer in the Controller in Rails/RoR?

Upvotes: 1

Views: 2792

Answers (4)

DGM
DGM

Reputation: 26979

The basic idea is to keep your controllers as thin as possible. Mostly that means that the controller accepts data from the network, and sets up variables needed in the view, and chooses the view.

The process of determining a role, an admin, etc, is a question to ask of a model... probably something like User, or Role, etc. The logic of how that is determined is in the models. The controller coordinates with this information to select a view or redirect if not allowed, etc.

Sometimes I find myself in a controller, doing a complex query to get a certain set of records. That's a code smell that I need to take that query and make a scope or a method in a model somewhere.

If you find yourself chaining a lot of calls on a model, it's probably time to move it to the model. If you find yourself opening up a lot of records, making decisions, and updating records, it's probably time to move to model.

If it's needed to decide what view to show the user (or whether to show it!), the controller is just fine.

Upvotes: 2

RyanWilcox
RyanWilcox

Reputation: 13972

Business Logic to me means anything particular about the business processes that you need to implement in Ruby.

For example, if you have a site where people purchase tickets, you might have a business process that says, "A user can only buy one ticket, until the day of the event, after which he can buy up to 5, if tickets are still available". So you have to write that up in Ruby - it's Ruby code that is implementing a business rule.

In contrast, in the same system, you might have code that splits out a ticket as a PDF. I wouldn't consider that "business logic", because it's not a business workflow rule... yes there's business value in printing tickets as PDF, but it's not about the workflow of how the business processes work (or should work) to enable it to serve its customers better.

Where as that rule about buying only 1 ticket? That's a policy of this particular business, a business rule.

Your example, as @Vinnyq12 pointed out, is more of a Access Control description... which you could say might be a type of business logic, yes.

Upvotes: 0

Vinnyq12
Vinnyq12

Reputation: 1559

What you are talking about is Role Based Access Control which is a type of business logic.

Business logic would be the operations that get carried out when Models calls are made. The business logic is in the model, not the controller.

Upvotes: 5

Deepesh
Deepesh

Reputation: 5614

Business Logic is the layer of your application where all the control statement of your application is written. For example you have a simple application of Selling tickets online. Now when you are developing application you has some logic to be implemented for Selling tickets like date of booking should not be holiday. So this rule that you wont sale tickets for holiday is nothing but a Business logic. For details see this site http://en.wikipedia.org/wiki/Business_logic

Upvotes: 2

Related Questions