Learn the most popular programming language of the most popular Operating System: Windows

Ad

A Closer Look at Encapsulation

Object properties, methods and events make up what is known as the objects interface.  this interface may be considered the private view of the object and it describes how that object can be manipulated.  Objects also have a private view: the data and code that the object does not expose to public view, but retains in order to execute its functions.  When you invoke the clear method of a List Box control, for example, you do not know how the list box clears its contents.  It just does it and you know that it works.  To illustrate encapsulation, let’s conduct a brief and simple exercise.

  1. Start-->All Programs -->Microsoft Visual Basic 5.0-->Visual Basic 5.0
  2. Select Standard EXE Project from the Project Type Window.
  3. The Project Window is displayed with a Blank Form (Form1).
  4. Select the Text Box Tool from the Toolbox and draw a Text Box on Form1.
  5. Draw Another Text Box below the first Text Box.
  6. Select Start from the Run Menu.
  7. Set the insertion point in the upper text box and type Microsoft Visual Basic.
  8. Select the text you have written using your mouse (or hold the Shift key down and use the directional keys).
  9. Copy the selected text onto the Windows Clipboard (Ctrl+C).
  10. Using the Tab key, shift to the lower text box and paste the text (Ctrl+V) from the Clipboard into the lower text box.
  11. Using the Backspace key, delete part of the text that you pasted.
  12. You can maximize the Form to fit in the Application Window or minimize it to remain as an icon on the task bar.
  13. Click on the Close Button of the Form at the right top corner to stop running the program.

Consider all the functionality contained within this application without a single line of Visual Basic code being written.  Three windows, a form, and two text boxes, were created.  One of these windows, the form, uses the default colors specified in the Windows Control Panel.  This form can be resized, minimized into an icon, or maximized to fill the entire screen.  It can be moved around the screen with the mouse.

The two text boxes allow the user to erase existing text and type text.  Text could be copied and pasted.  The text controls even indicate the user’s location by displaying a cursor.

How does the Text Box control manage the insertion point?  How does it "know" to erase text when the Backspace key is pressed?  You don't know.  That's the private view of the Text Box object.  You don't really have to know the inner workings of the Text Box object.  It works, and you can use it to build your own applications.  That's the power of encapsulation!

Technorati Tags: ,,
Share:

No comments:

Post a Comment

Popular Posts

Search This Blog

Powered by Blogger.

Featured Post

Coded Statements and Methods

In the preceding procedure , you wrote several coded instructions, which introduced two different programming statements and a method: the D...

Recent Posts