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
  • What is wavelength?

    Wavelength is the distance between identical points, or adjacent crests, in the adjacent cycles of a waveform signal propagated ...

  • subnet (subnetwork)

    A subnet, or subnetwork, is a segmented piece of a larger network. More specifically, subnets are a logical partition of an IP ...

  • Transmission Control Protocol (TCP)

    Transmission Control Protocol (TCP) is a standard protocol on the internet that ensures the reliable transmission of data between...

Security
CIO
  • What is a startup company?

    A startup company is a newly formed business with particular momentum behind it based on perceived demand for its product or ...

  • What is a CEO (chief executive officer)?

    A chief executive officer (CEO) is the highest-ranking position in an organization and responsible for implementing plans and ...

  • What is labor arbitrage?

    Labor arbitrage is the practice of searching for and then using the lowest-cost workforce to produce products or goods.

HRSoftware
  • organizational network analysis (ONA)

    Organizational network analysis (ONA) is a quantitative method for modeling and analyzing how communications, information, ...

  • HireVue

    HireVue is an enterprise video interviewing technology provider of a platform that lets recruiters and hiring managers screen ...

  • Human Resource Certification Institute (HRCI)

    Human Resource Certification Institute (HRCI) is a U.S.-based credentialing organization offering certifications to HR ...

Customer Experience
Close