what is the difference between a class and a library?

后端 未结 3 943
野的像风
野的像风 2020-12-31 15:09

I googled, and was informed that a library is made up of multiple relevant classes. But in Codeigniter, I found that there is virtually only one Class in every Library. Sorr

3条回答
  •  耶瑟儿~
    2020-12-31 15:35

    The difference is a semantic one.

    A Class is an implementation of a specific piece of functionality (usually completely 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 that definition. Libraries can be procedural, functional or OOP. That doesn't detract from the fact that it's a library. Classes just help the abstraction when dealing with OOP.

    A Framework is a library that imparts architecture choices on how you write code.

    Every framework is therefore a library. Not every library is a framework. CodeIgniter itself can be used as a framework or a library. The difference is if you let the libraries direct your architecture, you're using a framework. If you do not use the architecture bit, it's a library.

    It's definitely a pedantic difference, but a significant one. As a gross-over-simplification, if you're doing a formal architecture and understand why everything is layered out how it is for your application specifically, you're using it as a library. If instead you're building it that way because that's how CI does it, that's using a framework. Both have significant benfits, but it's worth understanding the difference.

提交回复
热议问题