## Boilerplate code

In your code, the first step is to #include the needed headers: depending on your header include strategy, this can be as simple as `#include "maman-bar.h"` or as complicated as tens of #include lines ending with `#include "maman-bar.h"`:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    /*
     * Copyright information
     */

    #include "maman-bar.h"

    /* If you use Pimpls, include the private structure
     * definition here. Some people create a maman-bar-private.h header
     * which is included by the maman-bar.c file and which contains the
     * definition for this private structure.
     */
    struct _MamanBarPrivate {
      int member_1;
      /* stuff */
    };

    /*
     * forward definitions
     */

Call the `G_DEFINE_TYPE` macro using the name of the type, the prefix of the functions and the parent GType to reduce the amount of boilerplate needed. This macro will:

- implement the `maman_bar_get_type` function
- define a parent class pointer accessible from the whole .c file

    1
    G_DEFINE_TYPE (MamanBar, maman_bar, G_TYPE_OBJECT)

It is also possible to use the `G_DEFINE_TYPE_WITH_CODE` macro to control the get_type function implementation - for instance, to add a call to `G_IMPLEMENT_INTERFACE` macro which will call the `g_type_implement_interface` function, or call the `G_ADD_PRIVATE` macro will add an instance private data structure.