Programing

간단한 설명 PHP OOP 대 절차?

lottogame 2020. 8. 15. 09:45
반응형

간단한 설명 PHP OOP 대 절차?


PHP를 배우고 OOP와 절차에 대한 아이디어를 얻고 싶습니다. OOP와 Procedural에 대한 다른 블로그와 자습서를 읽었지만 여전히 접근 방식을 이해할 수 없습니다.

OOP 대 절차

  1. 무엇을 배워야합니까?
  2. 코드의 차이점은 무엇입니까? 효과는 무엇입니까?
  3. PHP 프레임 워크가 OOP 접근에 어떻게 도움이 될 수 있습니까? (CodeIgniter를 배우고 싶습니다)
  4. 절차에 프레임 워크가 필요합니까?

나는 둘 다의 코드 차이를 정말로 알고 싶다. OOP에 대한 나의 이해는 당신이 같은 클래스를 만들고 액세스 할 수 있다는 것입니다. (정확한지 모르겠습니다).

감사!


배경 : 다음을 제안하는 "간단한 설명"을 요청했습니다.

  1. 전문 용어없이 말도 안되는 개요 원합니다.
  2. 처음부터 배우는 데 도움이되는 무언가를 원합니다.
  3. 당신은 두 사람이 같은 방식으로 질문에 대답하지 않는다는 것을 발견 했고 그것은 혼란 스럽습니다. 그것이 당신이 여기에 간단한 설명을 요구하는 이유입니다. 예?

짧고 전문적이지 않은 답변 :

  1. 많은 소개 설명이 "OOP 실제 세계"예제로 빠르게 이동합니다. 도움이되는 것 이상으로 혼란 스러울 수 있으므로 지금은 무시해도됩니다.
  2. 소스 코드는 단순히 개별 파일에 저장되는 기능의 "덩어리"라고 생각할 수 있습니다.
  3. 이러한 "덩어리"를 구성하는 방법에는 여러 가지가 있습니다. 프로그래밍 언어의 관습, 개발자의 배경 및 교육 또는 평범한 개인 취향에 따라 다릅니다.
  4. OOP 및 절차 적 프로그래밍은 코드 "덩어리"를 구성하고 배열하는 방법에 대해 일반적으로 인식되는 두 가지 주요 방법론입니다.

긴 비전문가 답변 :

절차 적 대 OOP는 컴퓨터 프로그래밍의 근본적인 문제 중 하나 일뿐입니다. 코드를 이해 하기 쉽게 만드는 방법 과 전문적으로 유지 관리 할 수있는 케이크 조각입니다 . 실제로 OOP의 일부 원칙을 따르는 "절차 적"코드를 작성할 수 있으므로 두 가지가 반드시 반대되는 것은 아닙니다.

다른 객체 지향 프로그래밍 언어 를 배우면 이해가 커질 것입니다. 그중에서 PHP는 "블록의 새로운 아이"입니다.

다음은 경험을 구축하면서 배울 내용에 대한 간략한 개요 입니다.

  • 유용한 작업을 수행 하는 PHP 소스 코드를 작성할 수 있습니다.
  • 유용한 작업을 코드 "덩어리" 로 구성 할 수 있습니다.
  • 저장된 개별 파일과 관계없이 코드의 "덩어리"를 생각할 수 있습니다.
  • 때때로 이러한 코드 "덩어리"는 전달 하는 매개 변수에 따라 다르게 작동합니다 .
  • 매개 변수를 허용하는 코드 덩어리를 "함수"라고합니다.
  • 함수는 함께 "청크"될 수 있으며 이를 수행하는 다른 방법이 있습니다.
    • 예를 들어 , 평생 동안 작성한 모든 함수가 포함 된 하나의 큰 PHP 파일을 함수 이름에 따라 알파벳순으로 나열 할 수 있습니다.
    • 예 : 주제별로 함께 묶인 함수가있는 여러 PHP 파일을 가질 수 있습니다. [예 : 기본 문자열 조작을 수행하는 함수, 배열 처리를위한 함수, 파일 입력 / 출력을위한 함수 등]
  • OOP는 함수 를 "클래스"로 함께 "청크"하는 특별한 방법입니다.
  • 클래스는 통합 된 전체로 취급 할 수 있도록 함께 "청크" 코드 의 또 다른 수준입니다.
  • 클래스는 메서드속성 의 "청크"로 생각할 수 있습니다.

    • 메소드 는 단순히 의미있는 방식으로 서로 논리적으로 관련된 함수입니다. "방법"과 "기능"이라는 단어는 기본적으로 동일한 것을 나타내는 두 가지 다른 용어입니다.
    • 속성 은 단순히 클래스와 관련된 데이터 값입니다. 클래스의 함수 중 둘 이상 이 액세스 권한을 가져야 하기 때문에 의도적으로 개별 함수에 격리되지 않은 값입니다 .
      • 예를 들어 , 클래스에 천문학을 수행하는 여러 메서드가있는 경우 클래스의 속성은 모든 천문학 메서드가 알아야하는 특정 유명한 숫자의 값일 수 있습니다 (예 : Pi, 빛의 속도, 특정 행성 사이의 거리, 기타.).
    • 이것은 대부분의 OOP 설명이 " 실제 예제 " 로 분기되기 때문에 혼란스러워 지는 부분 입니다. 종종 "실제 세계"는 특정 개인의 존재 론적 관점에 대한 완곡 어법입니다. 즉 경향이 이미 개념을 이해 한 번만 유용한 다른 사람에게 가르 칠만큼 잘.
    • 혼란없이 OOP를 이해하려면 지금은 "실제"예제를 건너 뛰고 코드에만 집중하면됩니다. 클래스는 단순히 함수 (메서드라고도 함) 와 속성 (데이터라고도 함)을 하나 이상의 관련 "청크"에 PHP 코드 로 저장하는 방법입니다. 여기서 각 개별 "청크"는 특정 주제 또는 기능 부분을 처리합니다. 시작하기 위해 알아야 할 모든 것입니다.
  • 클래스는 코드 를 이해, 사용 및 유지 관리하기 쉬운 방식으로 매우 높은 수준 에서 구성 할 수 있기 때문에 유용 합니다.

  • When someone has written a lot of functions, and organized them into a lot of Classes, and gotten those to work together in some cool way, they package the whole thing together and call it a "Framework".
  • A Framework is just the next-highest level of "chunking" (including coding style and conventions) that one or more people agree on because they like the way the code is organized and it suits their working style, preferences, values, plans for world domination, etc.

See also


OOP is nothing more than a design pattern. If you're just beginning then learn the basics by focusing on the procedural approach. Most importantly, get familiar with basic principles like loops, conditions and calling other procedures.

While you're creating your procedural code, make a habit by adding related methods inside a single source file. Learn to divide your procedures into logical units and then you're already starting to become object-oriented. Basically, an object is nothing more than a collection of methods that are related to one another simply because they operate on the same set of data. (Not speaking of databases here, but application data!)

OO is mainly used to make your code more logical by dividing everything in simple blocks. By combining the right blocks, you get a complete application. OO isn't a silver bullet or golden hammer which will solve all your problems. But what it does do, is making your code easier to understand.

Then again, some people still manage to make a complete mess out of objects, simply by turning them into huge super-objects with hundreds of methods. Such objects don't differ much from a regular procedural approach, simply because of the huge amount of methods being combined together without any real logic. It's a mistake that's easy to make when people start doing OOP too fast.


You should learn both. Objects are just one of the many possible abstractions in existence, and abstraction is what programming is ultimately all about. That said, start with procedural stuff, and then add objects later, because PHP objects' internals are procedural anyway.

As for frameworks; first learn the fundamentals of the language, write throwaway experimental programs and such. Later you can familiarize yourself with frameworks and consider yourself whether you find some of them useful in some context. They definitely aren't mandatory.


Procedural php and oop uses the same php code. Then only difference is that with procedural, you focus on one task and that's it. In oop, you organize your code using patterns or chunks that can be re-used in many different areas of the code.

Simple answer is that, you need to know and understand php. You can learn it at php.net. Once you understand it, then you can start organizing your code in into chucks.

Procedural code uses functions, variables.

Once you get a hang of things, you can start organizing the functions and variables into classes. We start calling the functions as methods and variables as properties.

Good luck.


To add on the great answers above. You should see OOP as a natural progression of your coding style -when you start writing small program you might just need to put together a couple of lines of php code, then group them into functions and the more functions you write you may feel the need to better organize them into classes. OOP just let your structure your codes better -allowing a better code maintenance.

참고URL : https://stackoverflow.com/questions/1530868/simple-explanation-php-oop-vs-procedural

반응형