Browse Definitions :

class library (in object-oriented programming)

What is a class library (in object-oriented programming)?

In object-oriented programming, a class library is a collection of classes and other reusable software components, such as interfaces and value types. Developers can import class libraries or their components into their applications and use the prewritten code to carry out specific tasks.

A class library -- or, simply, library -- is analogous to a subroutine library in earlier procedural programming.

After importing a class library into an application, a developer can instantiate objects -- create real instance of them -- based on the classes within the library. The developer can then use those objects to access the methods and properties available to the classes.

structure and naming in object-oriented programming
Figure 1. Diagram illustrating an example of the structure and naming in object-oriented programming.

Example of object-oriented programming in action

For example, python-docx is an open source Python library that a developer or user can utilize to create and update Microsoft Word documents. After installing the library package on a system, the developer can import it into their Python scripts by issuing an import docx statement. They can then use the docx namespace to access the classes within the library. Figure 2 shows a simple Python script that demonstrates how to use the python-docx library to create a Word document and add initial content.

Python script showing how use the python-docx library
Figure 2. Screenshot showing a simple Python script that shows how to use the python-docx library to create a Word document and add initial content.

The script first imports the python-docx library and then defines the full path and file name for the new document, saving the path as a string to the test_doc variable. Next, the script instantiates an object based on the Document class in the docx namespace and assigns the object to the doc variable.

The doc variable is then used to call the add_heading and add_paragraph methods in the Document class. The add_heading method takes two arguments: the heading text and the heading level. The top-level heading is 0, the second-level heading is 1 and so on. The add_paragraph method also takes two arguments: the paragraph text and the paragraph style, which, in this case, is Normal. The paragraph text is passed into the method through the intro and section variables.

After adding the two headings and two paragraphs, the script uses the doc variable to call the save method in the Document class. The test_doc variable is passed in as an argument to the method. When you run the script, Python creates the specified Word document with the added content, as shown in Figure 3.

Python creates a specified Word document
Figure 3. Python creates the specified Word document with the added content when running the script.

If the python-docx library -- or something comparable -- were not available, every Python developer who needed to create or update a Word document in their scripts would have to spend the time necessary to develop these components themselves, even if they were all trying to achieve the same results. They could try sharing their code through other mechanisms, but these approaches often come with their own challenges.

How do class libraries simplify the job of the developer?

Class libraries greatly simplify the developer's job by providing access to code that performs specific tasks without having to invest in the time and effort needed to write the code from scratch. Many libraries are also available as open source projects, so they can be customized to meet a developer's or organization's specific requirements, which can be especially beneficial if using the library in multiple applications.

Programming languages typically include core class libraries that developers can access within their applications. Python, for example, comes with the Standard Library, which contains numerous built-in modules that are written in either C or Python and that provide access to a wide range of classes.

Another example is the Java Class Library, which includes a large collection of classes organized into packages of similar functionality. The packages are available at runtime to applications running in a Java virtual machine. Microsoft's .NET Framework also offers an assortment of class libraries that are available as either base class libraries that provide core capabilities or as framework class libraries that deliver a more complete set of classes.

Check out this breakdown of object-oriented programming concepts.

This was last updated in February 2023

Continue Reading About class library (in object-oriented programming)

  • CSU/DSU (Channel Service Unit/Data Service Unit)

    A CSU/DSU (Channel Service Unit/Data Service Unit) is a hardware device about the size of a modem. It converts a digital data ...

  • data streaming

    Data streaming is the continuous transfer of data from one or more sources at a steady, high speed for processing into specific ...

  • secure access service edge (SASE)

    Secure access service edge, also known as SASE and pronounced sassy, is a cloud architecture model that bundles network and ...

  • application blacklisting (application blocklisting)

    Application blacklisting --increasingly called application blocklisting -- is a network or computer administration practice used ...

  • juice jacking

    Juice jacking is a security exploit in which an infected USB charging station is used to compromise devices that connect to it.

  • hypervisor security

    Hypervisor security is the process of ensuring the hypervisor -- the software that enables virtualization -- is secure throughout...

  • recruitment process outsourcing (RPO)

    Recruitment process outsourcing (RPO) is when an employer turns the responsibility of finding potential job candidates over to a ...

  • human resources (HR) generalist

    A human resources generalist is an HR professional who handles the daily responsibilities of talent management, employee ...

  • employee lifecycle

    The employee lifecycle is a human resources model that identifies the different stages a worker advances through in an ...

Customer Experience
  • Adobe Experience Platform

    Adobe Experience Platform is a suite of customer experience management (CXM) solutions from Adobe.

  • virtual assistant (AI assistant)

    A virtual assistant, also called an AI assistant or digital assistant, is an application program that understands natural ...

  • inbound marketing

    Inbound marketing is a strategy that focuses on attracting customers, or leads, via company-created internet content, thereby ...