Tags:

ช่วยไขข้อข้องใจหน่อยครับ อ่านหลาย ๆ ที่แล้วยังสรุปไม่ได้

Get latest news from Blognone
By: mo.zeal
iPhoneWindows PhoneAndroidBlackberry
on 20 July 2009 - 18:38 #115214
mo.zeal's picture

Framework สามารถประกอบด้วย Library หลายๆ version รวมกันครับ

Mo.Zeal - cancerian-9 project

By: KnightBaron
ContributoriPhoneAndroidRed Hat
on 20 July 2009 - 19:07 #115220
KnightBaron's picture

เขียนโปรแกรมโดยการเรียกใช้ Library VS เขียนโปรแกรมให้ Framework เรียกใช้งาน

Yume Nikki

By: willwill
ContributorAndroid
on 20 July 2009 - 19:21 #115225
willwill's picture

เข้าใจว่า 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 นี่ครับ?

By: zdk
WriteriPhoneBlackberryUbuntu
on 20 July 2009 - 19:31 #115227
zdk's picture

ตาม 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});

By: m3rlinez on 21 July 2009 - 22:06 #115599 Reply to:115227

ชัดเจนครับ

By: Thaina
Windows
on 20 July 2009 - 20:51 #115239

เฟรมเวิร์คเป็นไลบรารี่ชนิดนึงครับ แต่เป็นไลบรารี่ที่กำหนดไว้ว่า เราต้องสร้างคลาสให้มีหน้าตาแบบที่มันต้องการ แล้วจะใช้งานมันได้แบบเต็มประสิทธิภาพ

อย่างใน C# มันจะบอกว่า จงใช้คำสั่ง Application.Run(new คลาส Form ที่เราสร้างไว้)

แล้วมันจะสั่งรัน Init() Show() ให้เรา เวลามีปุ่มโดนกด มันก็จะไปเรียก event ให้เรา ถ้าเรามีอะไรอยากทำกับปุ่มไหน ก็ไปเขียน Event เวลากดปุ่มปิดวินโดว์ มันก็จะมาดูว่าเราเขียนอะไรไว้มั้ย ถ้าเขียนไว้มันก็จะทำให้ อะไรแนวนี้

By: Ford AntiTrust
ContributorAndroidBlackberryUbuntu
on 20 July 2009 - 21:04 #115241
Ford AntiTrust's picture

เคยยกมาไว้ใน 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 ครับ

By: magicbank on 21 July 2009 - 23:02 #115617 Reply to:115241

โอว์ ตรงประเด็น และเข้าใจง่ายดีครับ

Framework เราต้องเขียน code ให้มันมาเรียกใช้เรา

Library เราต้องเรียกใช้ code ที่มันเขียนมาให้เราใช้

By: meawwat
ContributoriPhoneAndroidSymbian
on 23 July 2009 - 13:54 #115933
meawwat's picture

เป็นคำถามที่ดีมากเลยครับ

By: sukorn
Ubuntu
on 26 July 2009 - 20:36 #116536

ขอบคุณทุกคำตอบครับ กระจ่าง :)

By: sinisa on 27 July 2009 - 06:31 #116676

ขอบคุณทุกคำตอบ

By: akira on 28 July 2009 - 17:03 #116983

สุดยอดครับ เคลียร์เลย

By: EieiCM on 28 July 2009 - 17:43 #116992

ยอดเยี่ยมครับ .. เข้าใจก็คราวนี้แหละ (^_^)b