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
  • local area network (LAN)

    A local area network (LAN) is a group of computers and peripheral devices that are connected together within a distinct ...

  • TCP/IP

    TCP/IP stands for Transmission Control Protocol/Internet Protocol and is a suite of communication protocols used to interconnect ...

  • 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 ...

Security
  • identity management (ID management)

    Identity management (ID management) is the organizational process for ensuring individuals have the appropriate access to ...

  • single sign-on (SSO)

    Single sign-on (SSO) is a session and user authentication service that permits a user to use one set of login credentials -- for ...

  • fraud detection

    Fraud detection is a set of activities undertaken to prevent money or property from being obtained through false pretenses.

CIO
  • project scope

    Project scope is the part of project planning that involves determining and documenting a list of specific project goals, ...

  • core competencies

    For any organization, its core competencies refer to the capabilities, knowledge, skills and resources that constitute its '...

  • change management

    Change management is a systematic approach to dealing with the transition or transformation of an organization's goals, processes...

HRSoftware
  • recruitment management system (RMS)

    A recruitment management system (RMS) is a set of tools designed to manage the employee recruiting and hiring process. It might ...

  • core HR (core human resources)

    Core HR (core human resources) is an umbrella term that refers to the basic tasks and functions of an HR department as it manages...

  • HR service delivery

    HR service delivery is a term used to explain how an organization's human resources department offers services to and interacts ...

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