Which term describes the various characteristics of an object, such as size, color and type?

Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Understanding objects, methods, properties, and events

  • Article
  • 03/30/2022
  • 2 minutes to read

In this article

Objects and collections

An object represents an element of an application, such as a worksheet, a cell, a chart, a form, or a report. In Visual Basic code, you must identify an object before you can apply one of the object's methods or change the value of one of its properties.

A collection is an object that contains several other objects, usually, but not always, of the same type. In Microsoft Excel, for example, the Workbooks object contains all the open Workbook objects. In Visual Basic, the Forms collection contains all the Form objects in an application.

Items in a collection can be identified by number or by name. For example, the following procedure identifies the first open Workbook object.

Sub CloseFirst() 
 Workbooks(1).Close 
End Sub

The following procedure uses a name specified as a string to identify a Form object.

Sub CloseForm() 
 Forms("MyForm.frm").Close 
End Sub

You can also manipulate an entire collection of objects if the objects share common methods. For example, the following procedure closes all open forms.

Sub CloseAll() 
 Forms.Close 
End Sub

Returning objects

Every application has a way to return the objects it contains. However, they are not all the same, so you must refer to the Help topic for the object or collection that you are using in the application to see how to return the object.

Methods

A method is an action that an object can perform. For example, Add is a method of the ComboBox object, because it adds a new entry to a combo box.

The following procedure uses the Add method to add a new item to a ComboBox.

Sub AddEntry(newEntry as String) 
 Combo1.Add newEntry 
End Sub

Properties

A property is an attribute of an object that defines one of the object's characteristics, such as size, color, or screen location, or an aspect of its behavior, such as whether it is enabled or visible. To change the characteristics of an object, you change the values of its properties.

To set the value of a property, follow the reference to an object with a period, the property name, an equal sign (=), and the new property value. For example, the following procedure changes the caption of a Visual Basic form by setting the Caption property.

Sub ChangeName(newTitle) 
 myForm.Caption = newTitle 
End Sub

You can't set some properties. The Help topic for each property indicates whether you can set that property (read-write), only read the property (read-only), or only write the property (write-only).

You can retrieve information about an object by returning the value of one of its properties. The following procedure uses a message box to display the title that appears at the top of the currently active form.

Sub GetFormName() 
 formName = Screen.ActiveForm.Caption 
 MsgBox formName 
End Sub

Events

An event is an action recognized by an object, such as clicking the mouse or pressing a key, and for which you can write code to respond. Events can occur as a result of a user action or program code, or they can be triggered by the system.

See also

  • Visual Basic reference
  • Visual Basic conceptual topics

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.

What is object-oriented programming?

Object-oriented programming (OOP) is a computer programming model that organizes software design around data, or objects, rather than functions and logic. An object can be defined as a data field that has unique attributes and behavior.

OOP focuses on the objects that developers want to manipulate rather than the logic required to manipulate them. This approach to programming is well-suited for programs that are large, complex and actively updated or maintained. This includes programs for manufacturing and design, as well as mobile applications; for example, OOP can be used for manufacturing system simulation software.

The organization of an object-oriented program also makes the method beneficial to collaborative development, where projects are divided into groups. Additional benefits of OOP include code reusability, scalability and efficiency.

The first step in OOP is to collect all of the objects a programmer wants to manipulate and identify how they relate to each other -- an exercise known as data modeling.

Examples of an object can range from physical entities, such as a human being who is described by properties like name and address, to small computer programs, such as widgets.

Once an object is known, it is labeled with a class of objects that defines the kind of data it contains and any logic sequences that can manipulate it. Each distinct logic sequence is known as a method. Objects can communicate with well-defined interfaces called messages.

What is the structure of object-oriented programming?

The structure, or building blocks, of object-oriented programming include the following:

  • Classes are user-defined data types that act as the blueprint for individual objects, attributes and methods.
  • Objects are instances of a class created with specifically defined data. Objects can correspond to real-world objects or an abstract entity. When class is defined initially, the description is the only object that is defined.
  • Methods are functions that are defined inside a class that describe the behaviors of an object. Each method contained in class definitions starts with a reference to an instance object. Additionally, the subroutines contained in an object are called instance methods. Programmers use methods for reusability or keeping functionality encapsulated inside one object at a time.
  • Attributes are defined in the class template and represent the state of an object. Objects will have data stored in the attributes field. Class attributes belong to the class itself.
Which term describes the various characteristics of an object, such as size, color and type?
This image shows an example of the structure and naming in OOP.

What are the main principles of OOP?

Object-oriented programming is based on the following principles:

  • Encapsulation. This principle states that all important information is contained inside an object and only select information is exposed. The implementation and state of each object are privately held inside a defined class. Other objects do not have access to this class or the authority to make changes. They are only able to call a list of public functions or methods. This characteristic of data hiding provides greater program security and avoids unintended data corruption.
  • Abstraction. Objects only reveal internal mechanisms that are relevant for the use of other objects, hiding any unnecessary implementation code. The derived class can have its functionality extended. This concept can help developers more easily make additional changes or additions over time.
  • Inheritance. Classes can reuse code from other classes. Relationships and subclasses between objects can be assigned, enabling developers to reuse common logic while still maintaining a unique hierarchy. This property of OOP forces a more thorough data analysis, reduces development time and ensures a higher level of accuracy.
  • Polymorphism. Objects are designed to share behaviors and they can take on more than one form. The program will determine which meaning or usage is necessary for each execution of that object from a parent class, reducing the need to duplicate code. A child class is then created, which extends the functionality of the parent class. Polymorphism allows different types of objects to pass through the same interface.

What are examples of object-oriented programming languages?

While Simula is credited as being the first object-oriented programming language, many other programming languages are used with OOP today. But some programming languages pair with OOP better than others. For example, programming languages considered pure OOP languages treat everything as objects. Other programming languages are designed primarily for OOP, but with some procedural processes included.

For example, popular pure OOP languages include:

  • Ruby
  • Scala
  • JADE
  • Emerald

Programming languages designed primarily for OOP include:

  • Java
  • Python
  • C++

Other programming languages that pair with OOP include:

  • Visual Basic .NET
  • PHP
  • JavaScript

What are the benefits of OOP?

Benefits of OOP include:

  • Modularity. Encapsulation enables objects to be self-contained, making troubleshooting and collaborative development easier.
  • Reusability. Code can be reused through inheritance, meaning a team does not have to write the same code multiple times.
  • Productivity. Programmers can construct new programs quicker through the use of multiple libraries and reusable code.
  • Easily upgradable and scalable. Programmers can implement system functionalities independently.
  • Interface descriptions. Descriptions of external systems are simple, due to message passing techniques that are used for objects communication.
  • Security. Using encapsulation and abstraction, complex code is hidden, software maintenance is easier and internet protocols are protected.
  • Flexibility. Polymorphism enables a single function to adapt to the class it is placed in. Different objects can also pass through the same interface.

Criticism of OOP

The object-oriented programming model has been criticized by developers for multiple reasons. The largest concern is that OOP overemphasizes the data component of software development and does not focus enough on computation or algorithms. Additionally, OOP code may be more complicated to write and take longer to compile.

Alternative methods to OOP include:

  • Functional programming. This includes languages such as Erlang and Scala, which are used for telecommunications and fault tolerant systems.
  • Structured or modular programming. This includes languages such as PHP and C#.
  • Imperative programming. This alternative to OOP focuses on function rather than models and includes C++ and Java.
  • Declarative programming. This programming method involves statements on what the task or desired outcome is but not how to achieve it. Languages include Prolog and Lisp.
  • Logical programming. This method, which is based mostly in formal logic and uses languages such as Prolog, contains a set of sentences that express facts or rules about a problem domain. It focuses on tasks that can benefit from rule-based logical queries.

Most advanced programming languages enable developers to combine models, because they can be used for different programming methods. For example, JavaScript can be used for OOP and functional programming.

Developers who are working with OOP and microservices can address common microservices issues by applying the principles of OOP.

This was last updated in July 2021

Continue Reading About object-oriented programming (OOP)

  • Scala: Lightweight functional programming for Java
  • Choose the best programming language for DevOps workflows
  • To address microservices issues, turn to OOP principles
  • 10 of the best programming languages to learn in 2020
  • A breakdown of object-oriented programming concepts

Dig Deeper on Application development and design

  • Which term describes the various characteristics of an object, such as size, color and type?
    data abstraction

    Which term describes the various characteristics of an object, such as size, color and type?

    By: Robert Sheldon

  • Which term describes the various characteristics of an object, such as size, color and type?
    instantiation

    Which term describes the various characteristics of an object, such as size, color and type?

    By: Andrew Zola

  • Which term describes the various characteristics of an object, such as size, color and type?
    instance

    Which term describes the various characteristics of an object, such as size, color and type?

    By: Andrew Zola

  • Which term describes the various characteristics of an object, such as size, color and type?
    object

    Which term describes the various characteristics of an object, such as size, color and type?

    By: Peter Loshin

What are various characteristics of an object?

All individual objects possess three basic characteristics -- identity, state and behavior. Understanding these characteristics is crucial to knowing how objects and object-oriented logic work. Identity means that each object has its own object identifier and can be differentiated from all other objects.

Which term describes a set of instructions that lists steps that must be followed in a particular order starting at the beginning and continuing to the end?

syntax. The set of rules that must be followed when writing program instructions for a specific programming language is called: Structured.

What are the characteristics of an object in OOP?

Object-oriented methodology relies on three characteristics that define object-oriented languages: encapsulation, polymorphism, and inheritance.

How are the characteristics of an object represented in a class?

The object of a class is represented through the attributes. The term instantiation is used for creating various objects. Class is a blueprint of the objects. new keyword indicates an operator for dynamic allocation of an object.