Giter Club home page Giter Club logo

php-oop's Introduction

PHP OOP

History of programming language**

  • Functional
  • OOP
  • Procedural
  • Assembly
  • Matchine

Procedural

การทำงานเชิงกระบวนการ ทำงานแบบ โปรแกรมหลัก และ โปรแกรมย่อย (modules) โดยแต่ละ module จะออกแบบให้ทำได้ 1 งานเท่านั้น มี variable ทั้งแบบ global และ local โดย ตัวแปร global data สามารถให้โปรแกรมย่อยเรียกใช้ได้ ส่วนใหญ่เราจะเขียนกันแบบนี้ ปัญหาคือ ทำให้การควบคุมและเปลี่ยนแปลงค่าที่ก้อนข้อมูลชุดเดียวกันใน โปรแกรมหลัก ไม่รู้ว่า ฟังชั่นไหนเรียกใช้ หรือเปลี่ยนแปลงค่าข้อมูล ทำให้เกิดปัญหาได้เพราะทุกฟังก์ชั่นสามารถเรียกใช้ข้อมูลได้เหมือนกันหมด

OOP

Object oriented programming ภาษาเชิงวัตถุ แยก data กับ method ไว้ในแต่ละ object และสามารถกำหนดการเข้่าถึงข้อมูลในแต่ละ object ได้ ทำให้มีความปลอดภัยสูง ลดปัญหาการเปลี่ยนแปลงข้อมูลใน object โดยไม่ได้รับอนุญาต และในการสื่อสารระหว่าง object จะไม่สามารถเข้าถึง data ได้โดยตรง แต่จะต้องเข้าผ่าน method เท่านั้น และสามารถนำกลับมาใช้ซ้ำ (reuse) ได้ดีกว่า module

Procedural VS Object Oriented

  • กำหนดขั้นตอนการแก้ปัญหา มองปัญหาเป็นวัตถุ
  • โปรแกรมและข้อมูลอยู่คนละส่วน - เอาส่วนโปรแกรมและข้อมูลไว้ด้วยกัน
  • ออกแบบจากล่างขึ้นบน ออกแบบเป็นวัตถุ
  • แก้ไขง่ายเพราะมีอิสระต่อกัน การแก้ไขไม่กระทบส่วนอื่นๆ เพราะวัตถุมีความสมบูรณ์ในตัวเอง

องค์ประกอบพื้นฐาน

1.Class & Object (ต้นแบบและวัตถุ)

ประกอบด้วย 2 ส่วน คือ

  • คุณลักษณะ หรือคุณสมบัติ (attribute) / property
  • พฤติกรรม (method) / behavior

Class {Animal} -> Object {Tiger, Hippo, Bear}

{Animal} -> Elephant

Attribute: name, color, type, weight, leg

Method: run(), sleep(), makeSound()

Class {Employee} -> Object {Accounting, Programmer, Sale}

2.Method (เมธอด)

3.Encapsulation (การห่อหุ้ม)

4.Inheritance (การสืบทอดคุณสมบัติ)

5.Polymorphism (การพ้องรูป)

php-oop's People

Contributors

idreamba avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.