O'Reilly logo

CoffeeScript Application Development by Ian Young

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Managing display logic with classes

Looking at setup.coffee, we can see that a lot of the remaining code deals with formatting HTML output. A lot of it is specific to displaying animal descriptions, so let's start with that. We could move these functions to the Pet class, but it's considered a best practice to separate the business logic of your application from the display logic. Mixing data operations with display output tends to create tightly coupled code, making it very difficult to make changes to either the backend or the frontend later on.

Instead, we'll separate this logic into view classes. These will concern themselves with displaying the page and responding to user input, but will leave any manipulation of the data to the other classes. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required