Monday, December 6, 2021

Abstraction with JavaScript Objects

The previous project decomposed the drawing of a square into logical modules and implemented the modules as files containing global functions and variables. In software engineering, this solution process is referred to as functional decomposition, and the implementation is referred to as procedural programming. Procedural programming produces solutions that are well-structured, easy to understand, and often fast to create.

This is why it is often used to prototype a concept or to learn new techniques. This project enhances the Draw One Square solution with object-oriented analysis and programming to introduce data abstraction. As additional concepts are introduced and as the game engine complexity grows, proper data abstraction supports straightforward design and code reuse through inheritance. The JavaScript Objects Project This project demonstrates how to abstract the global functions and variables from the Draw One Square project into JavaScript objects.

This objected-oriented abstraction will result in a framework that offers manageability and expandability for subsequent projects. As illustrated in Figure 2-7, when running, this project displays a white rectangle in a greenish canvas, identical to that from the Draw One Square project. The source code to this project is defined in the Chapter2/2.4.JavaScriptObjects folder.

Abstracting the Game Engine

A completed game engine would include many self-contained subsystems to fulfill different responsibilities. For example, you may be familiar with or have heard of the geometry subsystem for managing the geometries to be drawn, the resource management subsystem for managing images and audio clips, the physics subsystem for managing object interactions, and so on.


In most cases, the game engine would include one unique instance of each of these subsystems, that is, one instance of the geometry subsystem, of the resource management subsystem, of the physics subsystem, and so on. These subsystems will be covered in later chapters of this book. This section focuses on establishing the mechanism and organization for implementing these single-instance or Singleton-like objects based on the JavaScript Module pattern.

Related Articles

Latest Articles

All Category