What is the difference between a class library and a framework

后端 未结 11 1922
别那么骄傲
别那么骄傲 2020-12-01 13:04

I hear the whole day the terms class library, base class library, Framework, ...
What highlights a framework and what a base class library?

相关标签:
11条回答
  • 2020-12-01 13:08

    Library:

    It is just a collection of routines (functional programming) or class definitions(object oriented programming). The reason behind is simply code reuse, i.e. get the code that has already been written by other developers. The classes or routines normally define specific operations in a domain specific area. For example, there are some libraries of mathematics which can let developer just call the function without redo the implementation of how an algorithm works.

    Framework:

    In framework, all the control flow is already there, and there are a bunch of predefined white spots that we should fill out with our code. A framework is normally more complex. It defines a skeleton where the application defines its own features to fill out the skeleton. In this way, your code will be called by the framework when appropriately. The benefit is that developers do not need to worry about if a design is good or not, but just about implementing domain specific functions.

    Library,Framework and your Code image representation:

    Library,Framework and your Code image relation

    KeyDifference:

    The key difference between a library and a framework is “Inversion of Control”. When you call a method from a library, you are in control. But with a framework, the control is inverted: the framework calls you. Source.

    Relation:

    Both of them defined API, which is used for programmers to use. To put those together, we can think of a library as a certain function of an application, a framework as the skeleton of the application, and an API is connector to put those together. A typical development process normally starts with a framework, and fill out functions defined in libraries through API.

    Original answer

    0 讨论(0)
  • 2020-12-01 13:17

    Often you use libraries to get a certain functionality in your OWN software/infrastructre. For example printing a barcode, you would use a library to do so. A framework abstracts a whole class of problems, perhaps the problem of writing web applications. To do so the framework delivers the "frame" with all functionality and stubs you can programm against.

    0 讨论(0)
  • 2020-12-01 13:21

    you call the code of class library where as framework calls your code

    0 讨论(0)
  • 2020-12-01 13:23

    I'd argue that the two are fairly interchangeable... - it is simply a set of common re-usable code (in whatever platform you are targetting), usually supplied by the platform.

    Maybe you could argue that the BCL usually represents the "pure" (vendor-independent) modules, where-as the "framework" may (depending on how you use the term) include the vendor's bespoke modules. But that it perhaps open to local interpretation.

    0 讨论(0)
  • 2020-12-01 13:24

    A class library usually is a DLL or a packet of classes that you can "include"/"reference" into your solution and reuse.

    A framework is usually a recurring pattern/solution targeted towards a specific context e.g. a GUI Framework. A framework more than often implies that you write certain pieces as dictated by the framework designers, slot them in the expected/correct places and it should work.

    • e.g. Spring is a framework for DI. You write xml files in a format dictated by the designers and then the framework allows you to obtain assembled classes without having to worry about the framework does it.
    • Rails is a framework in Ruby for RAD web-apps. You only write the models, controllers and views and you have a working web app in under an hour.
    • the BCL is a set of class libraries so that you don't have to implement data structures and frequently used types in .NET and just get the tested proven implementations for free by just including them.

    A framework usually contains multiple class libraries. As always, the terms are used in an ambiguous manner nowadays.. but the above represents the more common interpretation of the terms... mine atleast :)

    0 讨论(0)
  • 2020-12-01 13:27

    The distinguishing feature between a class library and a software framework is that in a framework, the flow of control is not determined by the user´s code, but by the framework.

    This is also known as Hollywood principle (don´t call us, we call you).

    By the way, there is also a nice Wikipedia article on this topic.

    0 讨论(0)
提交回复
热议问题