What is the difference between a class and a library?

I googled, and I was informed that the library consists of several relevant classes. But at Codeigniter, I found that there is only one class in each library. Sorry for my limited knowledge for this, but I would appreciate it if you could tell a little about it. Thank you very much!

+7
source share
3 answers

The difference is semantic.

A class is an implementation of a certain part of the functionality (usually fully encapsulating the functionality.

A library is a collection of units of functionality (or just one) that add functionality. Notice, I tried to stay away from the word class in this definition. Libraries can be procedural, functional, or OOP. This does not detract from the fact that this is a library. Classes just help abstraction when working with OOP.

A Framework is a library that provides a choice of architecture for writing code.

Thus, each structure is a library. Not every library is the foundation. CodeIgniter itself can be used as a structure or library. The difference is that if you let libraries guide your architecture, you use the framework. If you are not using a bit of architecture, this is a library.

This is definitely a pedantic difference, but significant. As a gross simplification, if you make a formal architecture and understand why everything overlaps the way it is specifically for your application, you use it as a library. If instead you build it that way, because, as CI does, it uses a framework. Both have significant advantages, but it’s worth understanding the difference.

+9
source

In general programming terms, not every library should consist of several classes. In fact, not all libraries should also consist of classes - it really depends on the implementation (and sometimes the language). As Wikipedia starts (italics mine):

In computer science, a library is a collection of resources used for software development. These may include routines, classes, values, or type specifications.

CodeIgniter has its own definition of "library", in which case it simply calls its own library for each third-party application. Despite this, you can include other classes in the same library file if you have at least one class with the same name as the library file.

+4
source

Checking CodeIgniter Documents :

When we use the term "Libraries", we usually refer to classes that are in the library directory and are described in the class description of this guide. In this case, however, we will describe how you can create your own libraries in your application / library directory in order to maintain a separation between your local resources and global structure resources.

I do not think of a “library” as a fixed number of classes or files. Does this quote refer to the specific use that confused you?

+1
source

All Articles