Browse Definitions :
Definition

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)

Networking
  • firewall as a service (FWaaS)

    Firewall as a service (FWaaS), also known as a cloud firewall, is a service that provides cloud-based network traffic analysis ...

  • private 5G

    Private 5G is a wireless network technology that delivers 5G cellular connectivity for private network use cases.

  • NFVi (network functions virtualization infrastructure)

    NFVi (network functions virtualization infrastructure) encompasses all of the networking hardware and software needed to support ...

Security
  • virus (computer virus)

    A computer virus is a type of malware that attaches itself to a program or file. A virus can replicate and spread across an ...

  • Certified Information Security Manager (CISM)

    Certified Information Security Manager (CISM) is an advanced certification that indicates that an individual possesses the ...

  • cryptography

    Cryptography is a method of protecting information and communications using codes, so that only those for whom the information is...

CIO
  • IT project management

    IT project management is the process of planning, organizing and delineating responsibility for the completion of an ...

  • chief financial officer (CFO)

    A chief financial officer (CFO) is the corporate title for the person responsible for managing a company's financial operations ...

  • chief strategy officer (CSO)

    A chief strategy officer (CSO) is a C-level executive charged with helping formulate, facilitate and communicate an ...

HRSoftware
  • HR automation

    Human resources automation (HR automation) is a method of using software to automate and streamline repetitive and laborious HR ...

  • compensation management

    Compensation management is the discipline and process for determining employees' appropriate pay and benefits.

  • HR technology (human resources tech)

    HR technology (human resources technology) is an umbrella term for hardware and software used to automate the human resource ...

Customer Experience
  • martech (marketing technology)

    Martech (marketing technology) refers to the integration of software tools, platforms, and applications designed to streamline ...

  • transactional marketing

    Transactional marketing is a business strategy that focuses on single, point-of-sale transactions.

  • customer profiling

    Customer profiling is the detailed and systematic process of constructing a clear portrait of a company's ideal customer by ...

Close