Difference between revisions of "Programming with Objects and Classes"

From Lazarus wiki
Jump to navigationJump to search
(Redirect to newer page name)
 
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
== Overview ==
+
#REDIRECT [[Object Oriented Programming with Free Pascal and Lazarus#Free Pascal Language Extensions]]
 
 
FPC includes several language extensions to its "standard" Pascal syntax to support object oriented programming. 
 
 
 
* Objects    (chapter 5)  [[Programming Using Objects]]
 
* Classes    (chapter 6)  [[Programming Using Classes]]
 
* Interfaces (chapter 7)  [[Programming Using Interfaces]]
 
* Generics  (chapter 8)  [[Programming Using Generics]]
 
 
 
These extensions are described in the indicated chapters of the FPC Language Reference Guide: http://www.freepascal.org/docs.var. Links to tutorial pages for each concept are included above as well.  The Language Reference Guide includes syntax diagrams and further details not contained in this introductory tutorial.  Of the four language features listed above, '''Objects''' and '''Classes''' form the basis of object oriented programming (OOP) in FPC and Lazarus.  For those new to OOP, the Objects section includes more introductory concepts and the Classes section minimizes repetition by emphasizing the similarities and differences to the Objects syntax.  In general, the '''Classes''' implementation seems to be more widely in use including Delphi ports and also Lazarus development.  Often the term "objects" are used to refer to what is actually the "class" dialect of OOP in FPC.  These documents will be worded to minimize any terminology confusion but outside of this document, the term "object" is often used to refer to "objects" created from a '''Class'''.  In fact the FPC run time library (RTL) includes a class library with a base '''class''' called ''TObject''.
 
 
 
Users familiar with the older Turbo Pascal OOP implementation may initially want to skip the section on Classes since the Objects implementation is based on the older Turbo Pascal dialect.  The section on  Classes should be familiar to Delphi users since it is based on Delphi syntax.  Be aware that some of the writeup in the Class section may refer to concepts from the Objects section.  For Mac developers familiar with the various Apple based Object Pascal dialects, neither the FPC Objects or Classes implementations provide a direct migration path. Currently, as of March 2009, there are discussions on the Mac Pascal Mailing list to potentially include some compiler support (new syntax) to  provide access to Apple's Objective C / Cocoa framework.
 
 
 
== General Concepts ==
 
 
 
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 ploymorphism."    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
 

Latest revision as of 05:11, 8 July 2016