760 likes | 918 Views
Discover the fundamentals and importance of object-oriented technology in software development, addressing the software crisis and innovative responses. Explore key concepts, principles, and methodologies for successful implementation.
E N D
Contents • Computational Model • Why object orientation • two responses to software crisis • Key 00 concepts • object, class, message passing, inheritance, encapsulation • What is “object oriented” • object oriented user interfaces • object oriented software design and analysis methods • object oriented databases • object oriented programming languages • object oriented integrated systems
Computational Model • Sequential programs • Assembly language, Pascal , C • Turing Machines • Recursive functions • Lisps • Recursive relations • Prologs, predicate calculus • Data Flow • Dataflow diagrams[Yourdon, DeMarco] • Pertri Nets, State machines
Conventional Programming:Imparative Programming Control data • Algorithm = Data + Control • Based on the computation model of von Neumann • machines: assembly language, FORTRAN, Pascal, C,etc • Centralized control - think globaly
Procedural Programming Programs Data โปรแกรมและข้อมูลอยู่คนละส่วน
Program Coding Integer Real Declaration Character Boolean Array Record ต้องประกาศชื่อตัวแปรทุกครั้ง
Program Coding Text & Numeric Declaration Data Input Records ต้องเขียนคำสั่งที่แตกต่างกัน เพื่อที่จะให้รับข้อมูลของแต่ละอุปกรณ์รับข้อมูล Image Sound Voice
Computing Procedure Function Program Coding โปรแกรมประยุกต์ขนาดใหญ่ ต้องเขียนคำสั่งประมวลผลข้อมูลต่อเนื่องกันหลายร้อยหรือหลายพันบรรทัด เมื่อเกิดข้อผิดพลาด ทำให้ยากต่อการค้นหา Declaration Data Input Processing Looping • If • Case Selection
Program Coding Declaration Text , Graphics and Animation Data Input Processing Sound Data OutPut Text & Graphics คำสั่งให้แสดงผล มีความยุ่งยากซับซ้อน ไม่แตกต่างไปจากการรับข้อมูล
Why object orientation • Software crisis • การพัฒนาของฮาร์ดแวร์เร็วมาก (the Moore law) • แต่การพัฒนาของซอฟต์แวร์ช้าและมี bug … • ในปี 1979 รัฐบาบ USA ใช้จ่ายในการพัฒนาซอฟต์แวร์ดังกราฟ Delivered , not used Payed, never finished Usefull with minor changes Major changes required
The reasons for software crisis • ช่องว่างระหว่าง users และ programmers • การเปลี่ยนแปลง(change) • การพัฒนาฮาร์ดแวร์ที่มีประสิทธิภาพมาก ทำให้ซอฟต์แวร์ที่ ต้องใช้ มีความซับซ้อนมากตามไปด้วย • The responses to the crisis : • วิศวกรรมซอฟต์แวร์ • paradigmsใหม่สำหรับ decomposition ของซอฟต์แวร์และการออกแบบและวิเคราะห์ปัญหา
Software engineering illustration of software engineering rationale Maintenance Maintenance Testing Testing Implementation Implementation Design
Software engineering • “art of computer programming” แบบเดิมถูกแทนด้วย engineering design และ planning techniques เพื่อใช้ในการพัฒนาโปรแกรม • สนับสนุนโดยซอฟต์แวร์ CASE (computer aided soft engineering) • Early software engineering • ไม่ให้เกิดการเปลี่ยนแปลงโดยพยายามใช้การหา requirementsและ design • สนับสนุนการใช้ re-use of components (programs, functions, objects) • management of complexity of software (decomposition) • OO software engineering • Plan for change, ease change • reuse of higher level components • new ways of decomposition
The cost of change 60 - 100 x Cost of change 1.5 - 6 x 1 x design development maintenance
Decomposition • เป็นวิธีการปกติที่มนุษย์ใช้แก้ปัญหาที่มีความซับซ้อนมาก ๆ • มีหลายวิธีที่ใช้สำหรับ software decomposition : • Function oriented • Focus : simulation some functional behavior of the real world • Information oriented • Focus : the abstraction (modeling) the information about the real world
Software decomposition (cont.) • Process oriented • focus : the (business) processes and interactions among participants • object oriented: • focus : objects which include information and functionality • component oriented: • focus : components of applications available to other software
History of OO • 1970s - basic research at Xerox PARC • 1981 - Smalltalk language - first popular OO language and operating system • 1984 - object Oriented GUI on Apple Macintosh • 1984 - C++ language … OO language to write real software • 1990s - development of C++ language and several OO analysis and design methods • 1995 - Java language … OO language for the Web
OO View of the world • The world can be broken into “objects” • e.g. a dog • objects are things : • we have information about (dog‘s name, age ...) • we do something to (ask a dog to fetch slippers) • objects are similar • all dogs are similar … they belong to a class of dogs • difference between a generic concept (dogs) and instances (Lessee) • classes are similar to other classes (e.g. all dogs are animals, all animals have age, so dogs have age too . )
OO View of the World (2) • วิธีการของ OO ทำให้เราเข้าใจสิ่งต่างๆในโลก, ปํญหาต่างๆรอบตัวเราในรูปของวัตถุ( objects) และ classes • to organize classes into hierarchies (Pluto, dog, animal) … from instance to a very generic term • the origins of object oriented view can be traced back to Aristotle • Man is a rational animal. • Man, animal … classes of things • animals … genus • rational … differential
OO and information modeling techniques • Constructs in information modeling techniques • entity, attribute, relationship … • can be mapped into OO constructs • object, data property, pointer to other object
What is an object? วัตถุ (object) เป็น collection ของ data (Attribute , properties) และ function logic ซึ่ง data จะบอกถึงคุณสมบัติหรือสถานะของ Object และ Method จะบอกถึงพฤติกรรมต่างๆของ object นั้นๆ
What is an object? (2) • object = data structure + behavior tight coupling • Software = Collection of objects that send each other messages m4 m1 m2 m3
What is an object(3) • Attribute คือข้อมูลที่เราสนใจเกี่ยวกับ Object นั้น • Method จะแบ่งเป็น 2 ประเภทคือ interface method (เป็น method ที่ถูกใช้ได้จาก Object อื่น) และ internal method (เป็น method ที่จะถูกเรียกใช้ได้เฉพาะภายใน Object ที่เป็นเจ้าของเท่านั้น) • ตัวอย่าง • circle : x, y, r, area() = 2,3,5,15 • a slide • a world document Circle #23223 x = 2 y = 3 r = 5 area()
Objects are defined by • Variables ใช้ในการเก็บข้อมูล • Methods ใช้ดำเนินการกับ data
วัตถุ The nature of object มีชีวิต ไม่มีชีวิต
นาฬิกาเรือนนี้เป็น วัตถุ (Object) ไม่มีชีวิต แต่ทำงาน (เดิน) ได้ เพราะมีกลไกที่จะทำให้เข็มทั้งสองเคลื่อนที่แบบสัมพันธ์กันได้
การกำหนด ขั้นตอน และวิธีที่จะให้กับนาฬิกาเดินได้ ทำได้ด้วยการบรรจุกลไก และ/หรือ กระแสไฟฟ้าเข้าไป เช่น เฟืองนาฬิกากับลาน หรือเฟืองนาฬิกากับกระแสไฟฟ้า การกระทำเช่นนี้เรียกว่า การกำหนดวิธีการกระทำ (Method) ให้กับวัตถุ
วัตถุที่ไม่มีชีวิต จะไม่เริ่มทำงานด้วยตัวเอง ถึงแม้จะใส่วิธีการกระทำไว้เรียบร้อยแล้ว หากต้องการให้วัตถุทำงาน ต้องมีเหตุการณ์ (Event) จากวัตถุอื่นมากระทบ
Message passing • คือการที่ วัตถุติดต่อกันด้วยการส่งข้อความ (message) ถึงกันและกันซึ่งข้อความจะประกอบด้วยจุดหมายปลายทาง (destination) ของข้อความนั้นและข้อมูลที่สำคัญ (argument หรือ parameter) • Message Passing เปรียบได้กับ function call หรือ procedure call ที่มีใน structured programming โดยผ่าน Interface • method ของ Object นั้นๆ มีผลทำให้Object ที่เป็นผู้รับข้อความ (received object) นั้นกระทำการอย่างใดอย่างหนึ่ง
Message passing • วัตถุหนึ่งสามารถส่ง message ถึงกันและกันได้ • RECEIVER determines the code to be executed • Procedural language: function name + scope code • OO language:message name + receiving object code
Object collaboration • messages ประกอบด้วย components ดังนี้ • address • method • parameters • the reply is an object What is your area ? 15.232
Features of objects • Identity • Classification • Inheritance • Polymorphism • Information hiding
Identity • Data is associated with discrete differentiable entities • Object has a built-in identity two objects with identical data are allowed • Object identity can be realized by unique name/key, pointer • Objects are accessed via the unique id mixed collections are possible
Class and Instance • Class เป็นพิมพ์เขียวของ Object ไม่สามารถนำมาใช้ได้โดยตรง โดยจะมีการบอกถึง Method ที่ใช้ได้โดย Object และมีการแสดง data type ที่บอกถึงสถานะของ Object โดยยังไม่ระบุค่าใน Attribute แต่ละตัว • ถ้าเป็น Objectจะมีการระบุค่าของ Attribute ที่แน่นอน
Classification • Class : Grouping of similar objects: same attributes (instance variables) same operations (services/messages) • Class: abstraction to relevant features • Definition of classes is determined by the application • Class describes (infinite) set of objects = instances of the class
Example: class polygon • class polygon • attributes • set of points • line color • fill color • operations • draw • delete • move
Objects and classes • วัตถุแบบเดียวกันจะอยู่ในclass เดียวกัน, วัตถุชนิดเดียวกันจะเป็นสมาชิกของ class เดียวกัน • circle เป็น class ของวัตถุซึ่งมี x,y,r และสามารถคำนวณหาพื้นที่ได้จากสูตร a = r2 • objects are instances of classes … circle number #23 at (x,y) = (2,3) with r = 5
Class versus type • OO type = protocol understood by an object = set of methods that are implemented • Class = implementation oriented construct • implements one or more types • Type: Used for specification
Features of object oriented systems • Classes เป็น abstract data types • Concept และ implementation ของclass จะแยกจากกัน • Classes มีลักษณะ hierarchically ordered, Child classes สืบทอดคุณสมบัติ (data, methods) จาก parent classes • circle class from shape class • การเข้าถึงคุณสมบัติของวัตถุขะถูก controlled. คุณสมบัตินี้คือ encapsulation และ data hiding.
Abstract data typing • Circle : x, y, r; area() • circle เป็นสิ่งที่มีข้อมูลประกอบด้วยตำแหน่งและรัศมี และ method ที่ใช้คำนวณพื้นที่ • จากนิยามของ Circle ข้างต้นcเราจะทราบถึงวิธีการคำนวณหาพื้นที่ • concept และ implementation จะถูกดำเนินการแยกจากกัน
Inheritance • การถ่ายทอดคุณสมบัติ คือการ class ที่ต่างกันมี attributes และ operations ที่เหมือนกันPublication Journal paper Book • Subclasses inherit all properties of the super class
Hierarchy of objects and inheritance • Shape : x, y; area() • shape เป็นสิ่งที่ประกอบด้วยข้อมูลคือ position และการ คำนวนหาพื้นที่ (area) • circle : shape, r • a circle is a shape which also has a radius • circle inherits some information from shape class but it should also define its own area routine • single and multiple inheritance
Inheritance CIRCLE SHAPE Is kind of draw radius draw Is kind of move center SQUARE uses draw VERTEX edge move x y
Separation of concept and implementation • Class declaration what is a circle • class definition - how you calculate circle’s methods • object definition - creation a new circle with an ID and at a certain position in space
รถยนต์ มีสี่ล้อขึ้นไป มีพวงมาลัย มีเกียร์ มีน้ำมันเชื้อเพลิง มีแบตเตอรี มีแบตเตอรี มีน้ำมันหล่อลื่น มีไดนาโม
Advantages of inheritance • Avoiding redundancies • Identical code must only be written once • Reduced code size • Code reuse
Concept of generalization • Class: Implicitly defines a set of objects • aCar Car = Set of all cars • Generalization: Subset relation • Truck Car classification generalization aFordTruck Car Truck aMercedes
Encapsulation and data hiding • กำหนดว่าใครสามารถเห็นหรือใช้ data และ methods ของวัตถุนั้นได้ OBJECT OBJECT method 1 method 1 method 2 method 2 method 3 method 3 data 1 data 1 data 2 data 2 data 3 data 3 a. b.
รถยนต์ บิดกุนแจ สตาร์ท Event Methods Properties สตาร์ทเตอร์หมุน เก๋ง หัวฉีดจ่ายน้ำมัน สี่ประตู ลูกสูบทำงาน 1600 CC หัวฉีด ปั้มน้ำมันหล่อลื่น ทำงาน ABS ทั้งสี่ล้อ ปั้มน้ำระบายความร้อนทำงาน ล้อแมกซ์ สีแดง ไดนาโมจ่ายไฟเข้าแบตเตอรี แอร์ วิทยุ เทป