Programming with Objects and Classes/ru

From Lazarus wiki
Jump to navigationJump to search

English (en) français (fr) русский (ru)

Программирование с помощью объектов и классов

Краткий обзор

FPC включает в себя некоторые расширения языка в дополнение к "стандартному" синтаксису Pascal для поддержки объектно-ориентированного программирования.

Эти расширения описаны в главах документации по FPC - "Руководство по языку": http://www.freepascal.org/docs.var. Ссылки на страницы учебника для каждого понятия указаны выше. Руководство по языку имеет синтаксические диаграммы и другие детали, которые не включены в эту вводную статью. Из четырёх упомянутых выше особенностей языка, Objects и Classes - это базовые формы объектно-ориентированного программирования (ООП) в FPC и Lazarus. Для тех, кто не очень хорошо знаком с ООП, глава Objects включает наиболее общие концепции, а глава Classes минимизирует повторения, подчёркивая общие черты и различия с синтаксисом Objects. В общем случае Classes имеют наиболее частое применение, как у разработчиков Delphi, так и Lazarus. Часто слово "объект" фактически является "классом" в Classes диалекте ООП в FPC. Эти документы будут формулироваться так, чтобы минимизировать беспорядок в терминологии, но за пределами этого документа, термин "объект" часто относится к объектам-переменным, которые созданы на основе класса. Фактически FPC имеет библиотеку времени выполнения (RTL), включающую библиотеку классов основынных на классе с именем "TObject".

Пользователи, которые знакомы с ООП TurboPascal могут сначала пропустить главу о классах, т.к. работа собъектами основана на на диалекте старого Turbo Pascal. Глава о классах заинтересует пользователей Delphi, т.к. основана на синтаксисе Delphi. Be aware that some of the writeup in the Classes section may refer to concepts from the Objects section. For Macintosh developers familiar with the various Apple, THINK and MPW Object Pascal dialects, neither the FPC Objects or Classes dialects provide a direct migration path. As of March 2009, there are discussions on the Mac Pascal Mailing list about potentially providing some compiler support (new syntax) for accessing Apple's Objective C / Cocoa framework.

Основные концепции

OOP provides different ways to manage and encapsulate data and to manage program flow compared with other available programming language features and constructs. OOP often lends itself to modeling certain applications such as Graphic User Interfaces (GUI's) and physical systems in a more natural feeling manner. However OOP is not appropriate for all applications. Program control is not as explicit as the more basic Pascal procedural constructs. To obtain the most benefit from OOP, understanding of large class libraries is often required which can entail a steep learning curve. Maintaining large OOP application code has its advantages and disadvantages compared to maintaining strictly procedural code. There are many sources for learning OO analysis, design and programming techniques which are beyond the scope of this guide.

There are numerous programming languages which incorporate OOP features as extensions or the basis of their language. As such, there are many different terms for describing OO concepts. Even within FPC, some of the terminology overlaps. In general, OOP usually consists of the concept of a programming object (or information unit) which explicitly combines and encapsulates a related set of data and procedures which act on the data. This data is usually persistent during program execution but with mechanisms to reduce some of the problems inherent in declaring global variables. In addition, OOP languages enable objects to be incrementally modified and/or extended based on previously defined objects. This feature is usually referred to by the terms inheritance and polymorphism. Many OOP languages use the terms method or message referring to procedures which belong to an object. Much of the power of OOP is realized by late (run time) dynamic binding of methods rather than compile binding. This dynamic binding of methods is similar to using procedural variables and procedural parameters but with greater syntactic cohesion, encapsulation with the data it is related to and also inheritance of behavior of previously defined methods. The following wiki pages provide a starting point for discovering more about analysis, design and programming in an object orient manner.

http://en.wikipedia.org/wiki/Object-oriented_programming

http://en.wikipedia.org/wiki/OOAD

http://en.wikipedia.org/wiki/Object_oriented_design