1 / 18

Object-Oriented Programming

Object-Oriented Programming. IUP02 At Exceep camp. class Car { private string carColor; private string carType; private string carStatus = “Stop”; public Car(string color,string type){ carColor = color; cartype = type; } public void drive (){

dexter-orr
Télécharger la présentation

Object-Oriented Programming

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. Object-Oriented Programming IUP02 At Exceep camp

  2. class Car { private string carColor; private string carType; private string carStatus = “Stop”; public Car(string color,string type){ carColor = color; cartype = type; } public void drive (){ carStatus = “Drive”; } public void stop(){ carStatus = “Stop”; } } การประกาศ class The vocabulary of OOP

  3. class Car { private string carColor; private string carType; private string carStatus = “Stop”; public Car(string color,string type){ carColor = color; cartype = type; } public void drive (){ carStatus = “Drive”; } public void stop(){ carStatus = “Stop”; } } Fields The vocabulary of OOP

  4. class Car { private string carColor; private string carType; private string carStatus = “Stop”; public Car(string color,string type){ carColor = color; cartype = type; } public void drive (){ carStatus = “Drive”; } public void stop(){ carStatus = “Stop”; } } Methods The vocabulary of OOP

  5. class Car { private string carColor; private string carType; private string carStatus = “Stop”; public Car(string color,string type){ carColor = color; cartype = type; } public void drive (){ carStatus = “Drive”; } public void stop(){ carStatus = “Stop”; } } Constructor The vocabulary of OOP

  6. class carTesting{ static void Main(string[] args){ Car camry = new Car(“Blue”,”Car”); Car vigo = new Car(“Green”,”Truck”); } camry.drive(); Console.WriteLine(“Camry status=”+ camry.carStatus); Console.WriteLine(“Vigo status=”+ vigo.carStatus); } Object camry กับ vigo คือ object Out put: Camry status=drive Vigo status=stop The vocabulary of OOP

  7. ภาษาไหนเป็น OOP ดูอย่างไร • OOP must provide support for 3 key language features 1.encapsulation 2.inheritance 3.dynamic binding

  8. Class • Class เหมือน พิมพ์เขียว ของ Object ที่จะเกิดขึ้น Example: Class Name: Car Field: carColor, cartype , carStatus Method: drive, stop • Car • - carColor:String • -carType:String • -carStatus:String • +drive() • +stop() An UML class diagram

  9. Object • An object is an actual instance of the class. • Object’s characteristics are behavior (defined by the class), state (the value of its attributes) and identity (a name). Example1: Car camry = new Car(“Blue”,”Car”); Car vigo = new Car(“Green”,”Truck”); /*Camry Fields carColor = Blue and carType = Car */ /*Vigo Fields carColor = Green and carType = Truck*/ Example2: Random ran = new Random(): Car - carColor:String -carType:String -carStatus:String +drive() +stop()

  10. camry carColor = “Blue” carType = “Car” carStatus = “Drive” vigo carColor = “Green” carType = “Truck” carStatus = “Stop” Object

  11. Class versus Objects Defines the properties and behavior for all instances (objects) of this class. Specific realization of the class James Brucker’s slide 03 object

  12. Inheritance • “Inheritance is a powerful concept that greatly enhances the potential reuse of existing software, thereby providing the possibility of significant increases in software development productivity.” (concepts of Programming Languages seventh edition Robert W. Sebesta) Archer (Parent) Camel Archer Horse Archer [Camel Archer & Horse Archer Extends Archer]

  13. Inheritance Camel Archer กับ Horse Archer จะมีความสามารถ เทียบเท่ากับArcher หรือ มีความสามารถมากกว่า Camel Archer +Camel riding Archer -HP -AP +Archery +walk Horse Archer +Hose riding

  14. EX1 public class CamelArcher : Archer EX2 public class Form1 : Form Ex1 CamelArcher จะเป็นตัวลูกของ Archer แล้วจะมีความสามารถเท่ากัน หรือมากกว่า Ex2 จากเมื่อวาน เราจะเห็นว่ามีการใช้งานของ inheritance เช่นFrom1 ของน้องๆ จะถ่ายทอดความสามารถต่างจากclass From Inheritance

  15. Vending machine • เครื่องขายของ ของเราจะประกอบด้วย • Class สินค้าต่างๆ เช่น Coke and Fanta • Class เครื่องขายของ • Class GUI

  16. ปุ่มสั่งสินค้า ปุ่มนี้เมื่อกด Class เครื่องขายของจะทำการดึง Method หรือ Field ของคลาส สินค้าเพื่อทำการคำนวณ เงินที่ต้องจ่าย ปุ่มcheck stock กดเพื่อให้ Class เครื่องขายของทำการเช็คสินค้ากับคลาสสินค้าต่างๆ Vending Machine

  17. private int price = 15; private int quantity = 100; public int getPrice(){ return price; } public int getQuatity(){ return quantity; } public void setQuatity(int number){ quantity = number } Setter กับ Getter ในการเข้าถึงข้อมูลที่ถูกprivate Getter ใช้ในการแสดงค้าตัวแบบที่อยู่ภายในClass Setter ใช้ในการsetค่าตัวแปรในClass Class สินค้า

  18. Web ที่แนะนำ • http://en.wikipedia.org/wiki/Object-oriented_programming • http://java.sun.com/docs/books/tutorial/java/concepts/index.html • http://bdn.borland.com/article/0,1410,31863,00.html • http://www.cs.indiana.edu/classes/c304/oop.html

More Related