> ## Documentation Index
> Fetch the complete documentation index at: https://codegeninc-fix-system-prompt-typo.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Inheritable Behaviors

Codegen uses a set of core behaviors that can be inherited by code elements. These behaviors provide consistent APIs across different types of symbols.

## Core Behaviors

* [HasName](/api-reference/core/HasName): For elements with [Names](/api-reference/core/Name) (Functions, Classes, Assignments, etc.)
* [HasValue](/api-reference/core/HasValue): For elements with [Values](/api-reference/core/Value) (Arguments, Assignments, etc.)
* [HasBlock](/api-reference/core/HasBlock): For elements containing [CodeBlocks](/api-reference/core/CodeBlock) (Files, Functions, Classes)
* [Editable](/api-reference/core/Editable): For elements that can be safely modified ([learn more](/building-with-codegen/the-editable-api))

<Note>These "behaviors" are implemented as inherited classes.</Note>

## Working with Names

The [HasName](/api-reference/core/HasName) behavior provides APIs for working with named elements:

```python theme={null}
# Access the name
print(function.name)  # Base name without namespace
print(function.full_name)  # Full qualified name with namespace

# Modify the name
function.set_name("new_name")  # Changes just the name
function.rename("new_name")    # Changes name and updates all usages

# Get the underlying name node
name_node = function.get_name()
```

## Working with Values

The [HasValue](/api-reference/core/HasValue) behavior provides APIs for elements that have values:

```python theme={null}
# Access the value
value = variable.value  # Gets the value Expression node
print(value.source)     # Gets the string content

# Modify the value
variable.set_value("new_value")

# Common patterns
if variable.value is not None:
    print(f"{variable.name} = {variable.value.source}")
```

## Working with Code Blocks

The [HasBlock](/api-reference/core/HasBlock) behavior provides APIs for elements containing code:

```python theme={null}
# Access the code block
block = function.code_block
print(len(block.statements))  # Number of statements
printS(block.source)
```

<Info>
  Learn more about [CodeBlocks and Statements
  here](/building-with-codegen/statements-and-code-blocks)
</Info>

## Working with Attributes

The [get\_attribute](/api-reference/core/Class#get-attribute) method provides APIs for attribute access:

```python theme={null}
# Common patterns
class_attr = class_def.get_attribute("attribute_name")
if class_attr:
    print(f"Class variable value: {class_attr.value.source}")
```

<Info>
  Learn more about [working with Attributes
  here](/building-with-codegen/class-api#class-attributes).
</Info>

## Behavior Combinations

Many code elements inherit multiple behaviors. For example, a function typically has:

```python theme={null}
# Functions combine multiple behaviors
function = codebase.get_function("process_data")

# HasName behavior
print(function.name)
function.rename("process_input")

# HasBlock behavior
print(len(function.code_block.statements))
function.add_decorator("@timer")

# Editable behavior
function.edit("def process_input():\n    pass")
```
