Search Flex Samples

Basics of object-oriented programming

Introduction to object-oriented programming

Object-oriented programming (OOP) is a way of organizing the code in a program by grouping it into objects--individual elements that include information (data values) and functionality. Using an object-oriented approach to organizing a program allows you to group particular pieces of information (for example, music information like album title, track title, or artist name) together with common functionality or actions associated with that information (such as "add track to playlist" or "play all songs by this artist"). These items are combined into a single item, an object (for example, an "Album" or "MusicTrack"). Being able to bundle these values and functions together provides several benefits, including only needing to keep track of a single variable rather than multiple ones, organizing related functionality together, and being able to structure programs in ways that more closely match the real world.

Common object-oriented programming tasks

In practice, object-oriented programming has two parts. One part is the strategies and techniques for designing a program (often called object-oriented design). This is a broad subject and is not discussed in this chapter. The other part of OOP is the actual programming structures that are available in a given programming language to build a program using an object-oriented approach. This chapter covers the following common tasks in OOP:

  • Defining classes
  • Creating properties, methods, and get and set accessors (accessor methods)
  • Controlling access to classes, properties, methods, and accessors
  • Creating static properties and methods
  • Creating enumeration-like structures
  • Defining and using interfaces
  • Working with inheritance, including overriding class elements

Important concepts and terms

The following reference list contains important terms that you will encounter in this chapter:

  • Attribute: A characteristic assigned to a class element (such as a property or method) in the class definition. Attributes are commonly used to define whether the property or method will be available for access by code in other parts of the program. For example, private and public are attributes. A private method can be called only by code within the class, while a public method can be called by any code in the program.
  • Class: The definition of the structure and behavior of objects of a certain type (like a template or blueprint for objects of that data type).
  • Class hierarchy: The structure of multiple related classes, specifying which classes inherit functionality from other classes.
  • Constructor: A special method you can define in a class, which is called when an instance of the class is created. A constructor is commonly used to specify default values or otherwise perform setup operations for the object.
  • Data type: The type of information that a particular variable can store. In general, data type means the same thing as class.
  • Dot operator: The period sign (.), which in ActionScript (and many other programming languages) is used to indicate that a name refers to a child element of an object (such as a property or method). For instance, in the expression myObject.myProperty, the dot operator indicates that the term myProperty is referring to some value that is an element of the object named myObject.
  • Enumeration: A set of related constant values, grouped together for convenience as properties of a single class.
  • Inheritance: The OOP mechanism that allows one class definition to include all the functionality of a different class definition (and generally add to that functionality).
  • Instance: An actual object created in a program.
  • Namespace: Essentially a custom attribute, allowing more refined control over which code can access other code.

0 comments:

Related Flex Samples

Learn Flex: Flex Samples | Flex Video Tutorials Flex Examples