class
Classes in Soul are defined using thesanctuary
keyword and provide object-oriented programming capabilities. They encapsulate data and behavior, support inheritance, and can be extended with traits.
Basic Class Definition
Classes are declared with thesanctuary
keyword:
Creating Class Instances
Instances are created using the.new()
method:
Constructor Method
The__genesis__
method is the constructor and is called when creating new instances:
Class Inheritance
Classes can inherit from other classes usingextends
:
Using Super
Thesuper
keyword calls methods from the parent class:
Static Methods
Classes can have static methods that belong to the class rather than instances:Class with Traits
Classes can use traits for code reuse:Private-like Methods
While Soul doesn’t have true private methods, you can use naming conventions:Class Properties
Properties can be accessed and modified directly:Class Methods Calling Other Methods
Methods can call other methods within the same class:Best Practices
- Use meaningful class names:
UserManager
instead ofManager
- Initialize all properties: Set initial values in
__genesis__
- Use super appropriately: Call parent methods when extending classes
- Keep methods focused: Each method should have a single responsibility