Nesting library into another custom library (best practice advice)

Hello,
this is a beginner question. I have never done this before so I am looking for some suggestions about best practices.

I am trying to understand how to move part of a code to a custom library.
Below is a short working version of my code as example.

This is the original code:

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_MOSI   9
#define OLED_CLK   10
#define OLED_DC    11
#define OLED_CS    12
#define OLED_RESET 13
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

void setup() {
  
  display.begin(SSD1306_SWITCHCAPVCC);
  display.display();
  
}

void loop() {
}

… which I would like to convert into something like this:

#include <PDisplay.h>

PDisplay pdisplay;

void setup(){
  pdisplay.initialize();
}

void loop(){
}

Below are the header and source.

PDisplay.h

#ifndef PDisplay_h
#define PDisplay_h

#include "Arduino.h"
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>


class PDisplay
{
  public:
    PDisplay();
    void initialize();
  private:
   
};

#endif

PDisplay.cpp

#include "PDisplay.h"

#define OLED_MOSI   9
#define OLED_CLK   10
#define OLED_DC    11
#define OLED_CS    12
#define OLED_RESET 13
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

PDisplay::PDisplay(){
}

void PDisplay::initialize(){
    display.begin(SSD1306_SWITCHCAPVCC);
    display.display();
}

As far as I can tell the cpp and h file you've posted here are not the only cpp and h files necessary. before you can try making any kind of custom library you will probably need to track down the various parts of libraries which the cpp and h files rely on, for example the definitions of display.begin() as well as what specifically the SSD1306_SWITCHCAPVCC argument does to this function.

Infraviolet:
before you can try making any kind of custom library you will probably need to track down the various parts of libraries which the cpp and h files rely on

Thanks for the reply!
I believe the code is working now (i mean the custom library) because all of these functions and variables you mention are somewhere inside the following includes:

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

declared on the header are found on the same “libraries” directory.