# Composition vs Inheritance

#### Composition:

1. It is a smaller pieces to create a big.
2. Defined as What it has.

![Composition](https://2037876129-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdbqCujxzeJqeQqlbM2%2F-LnkfLUL3Dlpp4CwR49G%2F-Lnkjs20aiJh0cgsYx2o%2Fimage.png?alt=media\&token=bfee4841-8ef7-4cc2-82a9-eecedf643d3e)

#### Inheritance:

1. It is that a super class is that extended to smaller pieces that add or override things.
2. Defined as What it is.
3. Tightly coupled, less code reusable. If any change in Base class will be useful or it may leads to code breakage.
4. Hierarchy issues.

![Inheritance](https://2037876129-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LdbqCujxzeJqeQqlbM2%2F-LnkfLUL3Dlpp4CwR49G%2F-LnkjflL5iFWmp4pLGtF%2Fimage.png?alt=media\&token=81d5c993-2257-4616-916f-21c821c674e7)


---

# 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://javascript-1.gitbook.io/javascript/composition-vs-inheritance.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.
