What are Objects?
Generally, objects are things. For example, a mobile is an object. Properties are nothing but the terms that describe and define a particular object. Our mobile, for example, has a color, a name, a model, camera, a height, and a weight. In Software, objects model real-world objects or abstract concepts. Examples: Bank, Account, Customer, Cat, Bicycle, etc.
Real-world objects have states and behavior. Account’ state: holder, balance, type and Account’ behavior: withdraw, deposit, suspend.
How do software objects implement real-world objects?
- Use variables/data to implement state
- Use methods/functions to implement behavior
An object is a software bundle of variables and related functions
The formal definition of an object type (class) as per definition by Google: Object types act as templates from which an instance of an object is created at run time. Types define the properties and functions define the behavior of the object.
Object types provide the structure for objects i.e. Define their prototype, act as a template. Object types define:
Set of attributes
- Represented by variables and properties
- Hold their state
Set of actions (behavior)
- Represented by methods/functions
- An object is a concrete instance of a particular object type
- Creating an object from an object type is called instantiation
- Objects have a state i.e. set of values associated with their attributes
- Type: Account
- Objects: Kathy’s account, John’s account
- Type: Fruits
What are Objects?
- There is no distinction between objects and classes
- Objects inherit from objects
- Even functions are objects
- Property (variable / field)
- Function (method)
An object that is defined/created by the developer to develop a software object model. developers can create their own objects, such as Bank Account, Student, houses, cars, companies, etc…
Built-in Objects / Predefined Objects
Common reference Objects
- Array Object
- Boolean Object
- Math Object
- Date Object
- Number Object
- String object
- Regular Expression Object
DOM (Data Object Model)
- Attributes Object
- Element Object
- Style Object
- Document Object
BOM (Browser Object Model)
- Windows Object
- Navigator Object
- Location Object
- Screen Object
- Storage Object
- values (properties);
- functions (methods);
Objects are containers with properties. properties can contain anything.
- Even functions
- Or other objects
- added by assigning to a new name;
- removed by assigning null to the name.
A new object is created by:
- Using object literal
- Using new Object() method
- Using an object constructor (using the new keyword)
- Using Object.create() method
- Using Factory Pattern/ Object Building Function
- Using Prototype Pattern
- objectName.propertyName and
Object.assign: recursive shallow overwrites for properties from the target, …objects
Object.is: like using the === operator, but true for NaN vs NaN, and false for +0 vs -0
Object.getOwnPropertySymbols: returns all own property symbols found on an object
Object.setPrototypeOf: changes prototype. Equivalent to Object.prototype.__proto__ setter
About the Author: Pranaya Rout
Pranaya Rout has published more than 3,000 articles in his 11-year career. Pranaya Rout has very good experience with Microsoft Technologies, Including C#, VB, ASP.NET MVC, ASP.NET Web API, EF, EF Core, ADO.NET, LINQ, SQL Server, MYSQL, Oracle, ASP.NET Core, Cloud Computing, Microservices, Design Patterns and still learning new technologies.