Classes

Classes encapsulate the object-specific structure and logic of entities in Cherrycake and in your application.

Additionally to your own class implementations, Cherrycake provides core classes for entities that are used throughout the engine and that you can use or extend in your application, like the Result class, which represents the result of an operation of any kind, or the Color class, which simply represents a color.

A more complex example of core classes is the Item class, which provides many useful methods to work with abstractions of objects, or the Items class, which provides methods to work with lists of Item objects.

Auto-loading

Classes are automatically loaded whenever they're needed, meaning you don't need to predict which classes you'll be using.

What's the difference between a class and a module?

Modules are intended to pack process-specific functionality, can be triggered with actions (see Lifecycle), can have configuration files and can even depend on other modules. Classes are intended to pack object-specific functionality, cannot be triggered with actions and don't get configuration files.

Example

If you're creating a social networking web application, the code to show the user profile page would go in a module you might want to call ProfilePage. In the other hand, you might want to have a User class to hold the information and the logic for that specific user.

In your architecture, the ProfilePage module will query the Database module for a specific user, and you'll get a User object in return. The ProfilePage module will then take care of building and showing the profile page using that User object, most probably using the Patterns module.

Last updated