1 / 102

INT2104 การพัฒนาโปรแกรมเชิงวัตถุ (Object Oriented Programming Development)

INT2104 การพัฒนาโปรแกรมเชิงวัตถุ (Object Oriented Programming Development). www.thawatchai.net/int2104. ธวัฒน์ชัย ศิลังค์ประชา. แนวการสอน.

farren
Télécharger la présentation

INT2104 การพัฒนาโปรแกรมเชิงวัตถุ (Object Oriented Programming Development)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. INT2104 การพัฒนาโปรแกรมเชิงวัตถุ (Object Oriented Programming Development) www.thawatchai.net/int2104 ธวัฒน์ชัย ศิลังค์ประชา

  2. แนวการสอน • ศึกษาแนวคิดหลักการเชิงวัตถุ( Introduction to Object-oriented) การจำลองสรรพสิ่งด้วยเทคนิคเชิงวัตถุ ความหมายวัตถุ(object)คลาส(class)กระบวนการ(Method) • วิธีกำหนดข้อมูลในรูปแบบต่างๆ การใช้คำสั่งต่าง ๆ

  3. แนวการสอน • การรับและแสดงผลข้อมูล โครงสร้างควบคุมการทำงาน ( Control Structures)การตัดสินใจ การวนรอบทำงานซ้ำ สตริง (String) อะเรย (Array) • การเขียนโปรแกรมเชิงวัตถุในการสืบทอด การนําคลาสมาใชงาน การใชงานไดหลายรูปแบบ(Polymorphism) การเขียนโปรแกรมเชื่อมโยงติดต่อฐานข้อมูล(MySQL)เบื้องต้น

  4. แผนการเรียน • วัตถุประสงค์ เพื่อให้ผู้เรียน มีความรู้ ทักษะ เกี่ยวกับ ศึกษาแนวคิดเกี่ยวกับหลักการเชิงวัตถุ( Introduction to Object-oriented ) การจำลองสรรพสิ่งด้วยเทคนิคเชิงวัตถุ ความหมายวัตถุ(object) คลาส(class) กระบวนการ(Method) เอนแคปชูเลชั่นการถ่ายทอดคุณสมบัติ กรรมวิธีโพลีมอร์ฟิซึม เทคโนโลยีจาวา

  5. วัตถุประสงค์ • การเขียนโปรแกรมเชิงวัตถุด้วยภาษาจาวา (Object Programming with Java) • โครงสร้างของโปรแกรมจาวา วิธีกำหนดข้อมูลในรูปแบบต่างๆ การใช้คำสั่งต่าง ๆ การรับและแสดงผลข้อมูล โครงสร้างควบคุมการทำงาน (ControlStructures)

  6. วัตถุประสงค์ • การตัดสินใจ การวนรอบทำงานซ้ำ การประมวลผลแบบสตริง (String)และอะเรย (Array) การเขียนโปรแกรมเชิงวัตถุในการสืบทอด การนําคลาสมาใชงาน • การใชงานไดหลายรูปแบบ(Polymorphism) การสร้าง packageใช้งานการเขียนโปรแกรมเชื่อมโยงติดต่อฐานข้อมูล(MySQL)เบื้องต้น

  7. เอกสารการเรียน • รายชื่อหนังสือและเอกสารประกอบการบรรยาย • ตำราหลัก Objects First with Java David Barnes & Michael Kolling 2009 เขียนโปรแกรม JAVA เบื้องต้น พิมพ์ครั้งที่ 2 ผู้แต่ง/แปล : วรเศรษฐ สุวรรณิก และคณะ,2550 • 2.Computing Concepts with Java Essentials 3rd,Cay Horstmann @John Wiley& Sons,Inc ISBN 0-471-24371-x

  8. แผนการเรียน (ต่อ) • ตำราประกอบตำราประกอบ 1.เขียนโปรแกรม JAVA เบื้องต้น พิมพ์ครั้งที่ 2 ผู้แต่ง/แปล : วรเศรษฐ สุวรรณิก และคณะ,2550 2.เรียนรู้โครงสร้างข้อมูลและอัลกอริทึมด้วย JAVA (ฉบับปรับปรุง) ผู้แต่ง/แปล : เนรมิตร ชุมสาย ณ อยุธยา 3.Java GUI using NetBeans วรเศรษฐ สุวรรณิก และคณะ,2551 4.เอกสารประกอบการสอนรายวิชา การเขียนโปรแกรมเชิงวัตถุด้วยภาษาจาวา อ.ธวัฒน์ชัย ศิลังค์ประชา 2551

  9. เอกสารและข้อมูลสำคัญ • เอกสารและข้อมูลสำคัญ • 1.เขียนโปรแกรม JAVA เบื้องต้น พิมพ์ครั้งที่ 2 • ผู้แต่ง/แปล : วรเศรษฐ สุวรรณิก และคณะ,2552 • 2 .เรียนรู้โครงสร้างข้อมูลและอัลกอริทึมด้วย JAVA (ฉบับปรับปรุง) • ผู้แต่ง/แปล : เนรมิตร ชุมสาย ณ อยุธยา • 4.Java GUI using NetBeans วรเศรษฐ สุวรรณิก และคณะ,2553 • 5.เอกสารประกอบการสอนรายวิชา การเขียนโปรแกรมเชิงวัตถุด้วยภาษาจาวา .ธวัฒน์ชัย ศิลังค์ประชา 2554 • 6.http://www.thawatchai.net/int2104.

  10. วิธีการวัดผลและประเมินผลวิธีการวัดผลและประเมินผล สอบย่อย สอบทั้งหมด 5 ครั้งๆ 5 คะแนนเป็น 15 คะแนน ขาดสอบ = 0 Midterm สอบกลางภาค 30 คะแนน งาน-ภาคปฎิบัติ 20 คะแนน งานเดี่ยว เวลาเรียน 5 คะแนน Final 30 คะแนน รวม 100 คะแนน

  11. ครั้งที่ 1 แนะนำ Java • ความเป็นมาของจาวา, แนวคิดของ "write once, run anywhere" • คุณสมบัติของภาษา Java • การรักษาความปลอดภัย • Java กับ World Wide Web • ขั้นของการศึกษาจาวา

  12. Object Oriented Technology Concepts

  13. Object • การมองเห็นสิ่งต่างๆเป็นวัตถุเป็นการมองที่เป็นธรรมชาติของมนุษย์ ภาพที่เราเห็นจะถูกแยกออกเป็นวัตถุต่างๆโดยอัตโนมัติ • ยกตัวอย่าง เช่น เมื่อเรามองไปที่โต๊ะทำงาน สมองของเราจะแยกส่วนต่างๆของภาพโต๊ะทำงานออกเป็น ปากกา, กระดาษ, แฟ้ม, ลิ้นชัก, โต๊ะ ฯลฯ

  14. Object • หรือเมื่อเราอยู่ในร้านอาหาร เราอาจจะเห็นบริกร, พนักงานเก็บสตางค์, พนักงานเข็นรถอาหาร เป็นต้น • บริกรทำหน้าที่รับออเดอร์จากลูกค้า, พนักงานเก็บสตางค์มีหน้าที่เก็บเงินและทอนสตางค์

  15. Object • เมื่อเรานึกถึงชื่อของวัตถุหรืออาชีพของคน เรามักจะคิดถึง คุณสมบัติ(Attribute)และความสามารถ ของวัตถุหรือคนเหล่านั้นขึ้นมาพร้อมๆกัน

  16. Object • เช่น เมื่อเรานึกถึงปากกา เราก็รู้ว่ามันมีสีอะไรและมันสามารถใช้เขียนได้

  17. และเมื่อเราต้องการทำอะไรบางอย่าง เราจะหาวัตถุหรือคนที่สามารถช่วยเราทำงานได้ เช่น ถ้าเราต้องการเขียน เราก็จะหาปากกาและกระดาษ, หรือถ้าเราต้องการอาหาร เราก็เรียกบริกรเข้ามารับออเดอร์ เราไม่จำเป็นต้องทราบการทำงานของปากกาว่ามันจ่ายหมึกออกมาได้อย่างไร • เหมือนกับที่เราไม่จำเป็นต้องทราบว่าเมื่อ บริกรรับออเดอร์จากเราไปแล้วเขาจะไปบอกพ่อครัวอย่างไร เราทราบแต่ว่าเมื่อเราตวัดปลายปากกา หมึกจะออกมา และเมื่อเราสั่งอาหาร เราก็(มัก)จะได้อาหารตามที่เราสั่งเสมอ

  18. เห็นได้ชัดว่าเราคุ้นเคยกับการแก้ปัญหาโดยใช้เครื่องมือหรือคนเป็นอย่างดี เนื่องจากการแก้ปัญหาจะทำได้ง่ายขึ้นเมื่อถูกเปลี่ยนให้อยู่ในมุมมองที่คุ้นเคย • ดังนั้นภาษาโปรแกรมที่เหมาะแก่การแก้ปัญหาหลายๆปัญหาก็ควรจะมีสนับสนุนการมองสิ่งต่างๆเป็นวัตถุด้วยภาษาที่สนับสนุนมุมมองดังกล่าว • เรียกว่าภาษาเชิงวัตถุ (Object-Oriented Programming Languages) ภาษา Java, C++, SmallTalk เป็นภาษาโปรแกรมเชิงวัตถุ

  19. Object & Class Object Object-Program Object:Real-world

  20. Anatomy of an Object(1) • An object is an abstraction and has an identity • An object has a name (which may or may not be unique) • An object is anything exhibits structure and behavior - Structure Attribute that define the object’s properties Each attribute takes on a single value for a given object - Behavior Operations performed on or by an object Each operation is implemented via a method Object can be related or linked to other objects

  21. Anatomy of an Object(2)

  22. Object Concept • Things Tangible Things =>Physical Things Intangible Things บทบาท(Tole) (อาจารย์ พนักงาน ผู้ป่วย) สิ่งอุบัติขึ้น(Incident) หรือ Event ต่างๆ เที่ยวบินฯ การโต้ตอบ(Interaction) (ตั้งแต่ 2 Object(ผู้ซื้อ-ขาย))

  23. 1.สิ่งที่เป็นรูปธรรม(จับต้องได้)1.สิ่งที่เป็นรูปธรรม(จับต้องได้) Object Tangible Things สิ่งที่จับต้องได้ เช่น สินค้า,ลูกค้า

  24. Intangible Things • บทบาท(Tole) (อาจารย์ พนักงาน ผู้ป่วย) • สิ่งอุบัติขึ้น(Incident) หรือ Event ต่างๆ เที่ยวบินฯ • การโต้ตอบ(Interaction) (ตั้งแต่ 2 Object(ผู้ซื้อ-ผู้ขาย)) • เที่ยวบิน • การวิ่ง • แสง • ความเป็นเจ้าของ 2.สิ่งที่เป็นนามธรรม(จับต้องไม่ได้) Object

  25. Object Concepts • Object = a “thing” that’s a member of a class • Examples … • Dwell here a while CLASS vs. OBJECT • Objects contain attributes + behaviors • Organization • Generalization/specialization hierarchies • Whole/part hierarchies

  26. Object & Class (Cont.) Person (Person) John Chan Person Mary Lee Person Nelson Sze Class Objects

  27. Object & Class (Cont.) • Attribute: • An observable property of objects in a class • Each object in the class has a value for each attribute • The value may or may not be unique for an individual object

  28. Object & Class (Cont.) Person (Person) John Chan 30 Person Mary Lee 24 Person Nelson Sze 60 Name: String Age: int Class with attributes Objects

  29. Object & Class (Cont.) • Operation • A function or transformation that may be applied to or by an object in a class; e.g. Debit, Credit • All objects in a class share the same operations • Each operation has the current object as an implicit argument

  30. Object & Class (Cont.) • Method - The implementation of an operation in a class • Query - An operation which merely computes a value without modifying any object

  31. Object & Class (Cont.) Person Name Age Attributes Change Job Change Address Get Address Get Job Operations

  32. Class and Object Employee Employee Employee name:String name=‘Smith’ name=‘Sharp’ age=24 age=52 age:Integer Class Employee Objects instantiated from the class Employee

  33. Professor Clark Representing Objects • An object is represented as rectangles with underlined names : Professor a + b = 10 a + b = 10 ProfessorClark Class Name Only ProfessorClark : Professor Object Name Only Class and Object Name (stay tuned for classes)

  34. What is a Class? • A class is a description of a group of objects with common properties (attributes), behavior (operations), relationships, and semantics • An object is an instance of a class • A class is an abstraction in that it: • Emphasizes relevant characteristics • Suppresses other characteristics OO Principle: Abstraction

  35. Sample Class Class Course Properties Name Location Days offered Credit hours Start time End time Behavior Add a student Delete a student Get course roster Determine if it is full a + b = 10

  36. Representing Classes • A class is represented using a compartmented rectangle a + b = 10 Professor Professor Clark

  37. Representing Classes in the UML • A class is represented using a rectangle with compartments. Professor J Clark

  38. Professor Smith Professor Mellon Professor Jones The Relationship Between Classes and Objects • A class is an abstract definition of an object • It defines the structure and behavior of each object in the class • It serves as a template for creating objects • Objects are grouped into classes Objects Class Professor

  39. Object Technology Abstraction Encapsulation Modularity Hierarchy Basic Principles of Object Technology จะกล่าวในรายละเอียดอีกครั้งเมื่อศึกษาถึงเรื่องต่างๆ เหล่านี้ภายหลัง

  40. About the Java Technology .?

  41. Write once, run anywhere "ถนนทุกสายมุ่งสู่ โลกอินเตอร์เนต เครื่องหลากหลาย ระบบปฏิบัติการต่างกัน" เราต้องการซอฟท์แวร์ที่ .. Consistently : แน่นอน ทำงานได้เหมือนกันในทุกที่ Anywhere on any platform : รันได้หลายที่ ในหลายระบบปฏิบัติการ Reliability : น่าเชื่อถือ Security : ปลอดภัย Low Risk: ความเสี่ยงต่ำ ไม่อันตราย เลือกใช้อะไรภาษาอะไรดี C++, JAVA, Small Talk, Object Pascal,VBasic ??? We choose "JAVA".

  42. Java technology is both a programming language and a platform. About the Java Technology .? Java Platforms A platform is the hardware or software environment in which a program runs.

  43. A Virtual Machine • ภาษาจาวาเป็นทั้ง Compiler และ Interpreter Compiler : ต้อง Compile ก่อนการใช้งาน แต่ Compile เป็น ByteCode Interpreter : การรันโปรแกรมจาวา ByteCode ของจาวาจะถูก Load เมื่อมีการเรียกใช้เท่านั้น คำสั่งใน ByteCode จะถูกแปลอีกครั้งในขั้นตอนการรัน

  44. Binary File Source Code Binary File Pentium Compiler(Pentium) Binary File PowerPC Compiler(PowerPC) SPARC Compiler(SPARC) Byte Code and Java Virtual Machine • Existing Development Environment %cc Hello.c –o Hello % Hello Binary Code Run

  45. Java Interpreter Java Code Java Compiler (Pentium) Pentium Java ByteCode (Independent on Platform) Java Interpreter Java Compiler (PowerPC) PowerPC Java Interpreter SPARC Java Compiler (SPARC) Bytecodes and the Java Virtual Machine • Java Development Environment %javac Hello.java Hello.class created % java Hello JVM Byte Code Run

  46. Java is Cross-Platform?

  47. Java • Source Code Java Bytecode JIT Compiler or Interpreter Compiler (javac) Execution Java Bytecode Java is Cross-Platform? • Truth: Java programs can compile to machine-independent bytecode • Truth: All major operating systems have Java runtime environments • Most bundle it (Solaris, MacOS, Windows 2k, OS/2) Compile Time Run Time

  48. Java Platforms • สามารถทำงานบน OS และ Platform ที่ต่างๆ กันได้ โดยไม่ต้อง Compile ใหม่ (Write One - Run Anywhere) • สามารถรันบน Web Page • สามารถรันบนอุปกรณ์ที่มี Java Virtual Machine เช่น โทรศัพท์มือถือ หุ่นยนต์

  49. องค์ประกอบเทคโนโลยีจาวา(Java Technology?) 1. Java Virtual Machine (JVM) 2. Java Runtime Environment (JRE) 3. Java 2 Software Developer Kit (J2SDK)

  50. 1. Java Virtual Machine (JVM) เป็นส่วนที่ทำหน้าที่เป็นตัวอินเตอร์พรีเตอร์ (interpreter)– เป็นส่วนที่ทำหน้าที่เป็นตัวอินเตอร์พรีเตอร์ (interpreter) คือ จะทำการแปลจาวาไบต์โค้ด ให้เป็นภาษาเครื่องเข้าใจ– จาวาไบต์โค้ดสามารถรันได้หลายแพลตฟอร์ม ถ้าแพลตฟอร์มนั้นมี JVM

More Related