A framework is more than a library, and actually maybe has nothing to do with a library.
Here is an interesting article on Martin Fowler’s blog about Inversion of control, but in the article, Martin discuss the difference between the library and the framework, as well he refers to another article about frameworks.
I can summarize the points in both articles in the following:
A library is about reusable functionalities, but a framework is about reusable behaviors.
A library is something you call/inherit from your code, but framework is something that calls your code or provide services for your code.
A library is a collection of components and classes, where framwork is how abstract classes and components interact with each others.
I can explain the framework by this definition: Framework is an abstract design that embodies how the application works, and it has "hooks" where you can "inject" your module, or component.
Framework สามารถประกอบด้วย Library หลายๆ version รวมกันครับ
Mo.Zeal - cancerian-9 project
เขียนโปรแกรมโดยการเรียกใช้ Library VS เขียนโปรแกรมให้ Framework เรียกใช้งาน
Yume Nikki
เข้าใจว่า framework คือ "frame" (กรอบ) นั่นแหละครับ คือโปรแกรมเราจะต้องเขียนตามกรอบนั้นๆ (อาจจะฉีกกรอบมานิดหน่อยได้) เช่น web.py ผมจะ output ก็ต้อง return ค่าออกมา ไม่สามารถ print ออกไปตรงๆ เพื่อแสดงบนหน้าเว็บได้ครับ และการเขียนผมก็ต้องเขียน class มารองรับ, สร้าง url mapping และเรียกตัว web.py ให้ทำงานครับ ถ้าไม่เรียก มันก็ไม่เกิดอะไรเท่านั้นเอง ถ้าคลาสไม่มีเมธอดที่ต้องการ มันก็ error หรือไม่สร้าง mapping มันก็คืน 404 ครับ
ส่วน Library เป็นอะไรที่เราจะไปเรียกเมื่อจะใช้ แต่จะเขียนตัวโปรแกรมหลักอย่างไรก็ได้ เช่น urllib เราอาจจะจัด format code ยังไงก็ได้ ให้ output เป็น cli, gtk, qt ก็ได้ แต่พอจะดึง url ก็สามารถ import urllib เข้ามา แล้วใช้ urllib.urlopen ดึงมาได้ครับ
จริงๆ แล้ว framework หลายๆ ตัว อย่าง django มันเป็น loose coupling นะครับ คือดึงเป็นชิ้นๆ มาใช้ได้ อย่างผมเคยเอา temputa ที่ใช้ใน paste มาทำ template ครับ และบาง framework ก็เป็น library มากองๆ กัน อย่าง TurboGears, Pylons ซึ่งมันก็เอาที่มีอยู่ใน Python แล้วมาต่อกัน และพัฒนาต่อยอดขึ้นไปครับ
เอ ... แล้ว widget toolkit ต่างๆ นี่มันก็เข้าทำนองของ framework นี่ครับ?
ตาม http://en.wikipedia.org/wiki/Software_framework
ที่ต่างกันอย่างชัดเจนคือเรื่อง flow of control -ถ้าเป็น framework ตัว framework จะเป็นคนจัดการ flow ทั้งหมดโดยเรียกไลบรารี่โค้ดและโค้ดของเราเข้าไปเป็นส่วนหนึ่งของ flow
Framework.call({Your code});
ตาม concept -> http://en.wikipedia.org/wiki/Hollywood_Principle
-แต่ถ้าเป็นไลบรารี่เราจะเป็นคนจัดการ flow เอง เรียกไลบรารี่เอง ตัดสินใจเอง
You.call({Library code});
ชัดเจนครับ
เฟรมเวิร์คเป็นไลบรารี่ชนิดนึงครับ แต่เป็นไลบรารี่ที่กำหนดไว้ว่า เราต้องสร้างคลาสให้มีหน้าตาแบบที่มันต้องการ แล้วจะใช้งานมันได้แบบเต็มประสิทธิภาพ
อย่างใน C# มันจะบอกว่า จงใช้คำสั่ง Application.Run(new คลาส Form ที่เราสร้างไว้)
แล้วมันจะสั่งรัน Init() Show() ให้เรา เวลามีปุ่มโดนกด มันก็จะไปเรียก event ให้เรา ถ้าเรามีอะไรอยากทำกับปุ่มไหน ก็ไปเขียน Event เวลากดปุ่มปิดวินโดว์ มันก็จะมาดูว่าเราเขียนอะไรไว้มั้ย ถ้าเขียนไว้มันก็จะทำให้ อะไรแนวนี้
เคยยกมาไว้ใน blog ครับ ที่ http://www.thaicyberpoint.com/ford/blog/id/475/
Library vs. Framework (http://techembassy.blogspot.com/2006/05/library-vs-framework.html)
A framework is more than a library, and actually maybe has nothing to do with a library.
Here is an interesting article on Martin Fowler’s blog about Inversion of control, but in the article, Martin discuss the difference between the library and the framework, as well he refers to another article about frameworks.
I can summarize the points in both articles in the following:
A library is about reusable functionalities, but a framework is about reusable behaviors.
A library is something you call/inherit from your code, but framework is something that calls your code or provide services for your code.
A library is a collection of components and classes, where framwork is how abstract classes and components interact with each others.
I can explain the framework by this definition: Framework is an abstract design that embodies how the application works, and it has "hooks" where you can "inject" your module, or component.
สรุปง่ายๆ คือ library เราเป็นคนใช้ code ของมันเป็นหลัก ส่วน framework เราเป็นคนเขียน code ให้มันเอาไปใช้
library คือส่วนกลับของ framework ครับ
โอว์ ตรงประเด็น และเข้าใจง่ายดีครับ
Framework เราต้องเขียน code ให้มันมาเรียกใช้เรา
Library เราต้องเรียกใช้ code ที่มันเขียนมาให้เราใช้
เป็นคำถามที่ดีมากเลยครับ
ขอบคุณทุกคำตอบครับ กระจ่าง :)
ขอบคุณทุกคำตอบ
สุดยอดครับ เคลียร์เลย
ยอดเยี่ยมครับ .. เข้าใจก็คราวนี้แหละ (^_^)b