# Classes guide

Classes encapsulate [object-specific logic](/architecture/classes.md), and they also come in two flavors:

* [**Core classes**](/reference/core-classes.md)
  * Ready-made classes provided by Cherrycake, providing useful object entities to interact with Cherrycake functionalities like the [Action](/reference/core-classes/action.md) or the [RequestParameter](/reference/core-classes/requestparameter.md), and other generalist classes to use throughout your code like the [Item](/reference/core-classes/item.md) or the [Image](/reference/core-classes/image.md) classes.
* **App classes**
  * Classes created by the developer to encapsulate object logic, often inheriting from core classes like [Item](/reference/core-classes/item.md).
  * For example, in an e-commerce web application you might need a `Product` class, a `ProductCategory` class and perhaps a `CartItem` class, all them might extend the [Item](/reference/core-classes/item.md) core class.

## Loading classes

Classes are automatically loaded the first time they're used, so you don't have to worry to include them anywhere.

For example, to create an [Image](/reference/core-classes/image.md) object, just do this anywhere in your code:

```php
$image = new \Cherrycake\Image;
```

Likewise, to create an object of a class you've created (an App class), just remember to specify our app's namespace instead of `\Cherrycake\`:

```php
$product = new \CherrycakeApp\Product;
```

You can also add `use` statements at the top of your file so you don't need to prefix class names each time you want to use them, like this:

```php
use Cherrycake;

$image = new Image;
```

## App class files

The App classes you create must be stores in the `/src` directory of your app, and the file name must match the class name, plus the `.php` extension. Unlike modules, classes do not need their own directory under `/src`.

> Note that class file names are case-sensitive.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cherrycake.tin.cat/guide/classes-guide.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
