View on GitHub

reading-notes

class 7

Domain modeling

Domain modeling is the process of creating a conceptual model in code for a specific problem. A model describes the various entities, their attributes and behaviors, as well as the constraints that govern the problem domain. An entity that stores data in properties and encapsulates behaviors in methods is commonly referred to as an object-oriented model.

Define a constructor and initialize properties

To define the same properties between many objects, you’ll want to use a constructor function.

let functionName = function(x, y) {
  this.x = x;
  this.y = y;
}
// creating new objects
let instance1 = new functionName(7, false);
let instance2 = new functionName(4, true);

console.log(instance1);
console.log(instance2);

As you can see, the constructor function is defined using a function expression. When the function is called, the data inside these parameters are stored inside the this.x and this.y properties respectively. Storing data within properties ensures any newly created object can access that data later.
After the constructor function definition, two objects are instantiated with the new keyword and their properties are initialized by calling the constructor function.
This is object-oriented programming in JavaScript at its most fundamental level.

  1. The new keyword instantiates (i.e. creates) an object.
  2. The constructor function initializes properties inside that object using the this variable.
  3. The object is stored in a variable for later use.

Domain modeling is the process of creating a conceptual model for a specific problem. And a domain model that’s articulated well can verify and validate your understanding of that problem.

Here’s some tips to follow when building your own domain models.

  1. When modeling a single entity that’ll have many instances, build self-contained objects with the same attributes and behaviors.
  2. Model its attributes with a constructor function that defines and initializes properties.
  3. Model its behaviors with small methods that focus on doing one job well.
  4. Create instances using the new keyword followed by a call to a constructor function.
  5. Store the newly created object in a variable so you can access its properties and methods from outside.
  6. Use the this variable within methods so you can access the object’s properties and methods from inside.

Tables

There are several types of information that need to be displayed in a grid or table. When representing information in a table, you need to think in terms of a grid made up of rows and columns.
What’s a Table?

A table represents information in a grid format. Examples of tables include financial reports, TV schedules, and sports results.

Table structure:

Spanning columns & rows

long Tables

There are three elements that help distinguish between the main content of the table and the first and last rows (which can contain different content).

Objects

creating an object using the new keyword from the constructor as before,

this
The keyword this is commonly used inside functions and objects. Where the function is declared alters what this means. It always refers to one object, usually the object in which the function operates.

arrays

arrays are actually a special type of objects, they hold a related set of key/value pairs, but the key for each value is its index number. you can combine arrays and objects , arrays can store a series of objects and objects can also hold arrays.
WHAT ARE BUILT-IN OBJECTS?
Browsers come with a set of built-in objects that represent things like the browser window and the current web page shown in that window. These built-in objects act like a toolkit for creating interactive web pages.
There are three groups of built in objects :

  1. BROWSER OBJECT MODEL: The Browser Object Model contains objects that represent the current browser window or tab. It contains objects that model things like browser history and the device’s screen.
  2. DOCUMENT OBJECT MODEL:
    The Document Object Model uses objects to create a representation of the current page. It creates a new object for each element (and each individual section of text) within the page.
  3. GLOBAL JAVASCRIPT OBJECTS:
    The global JavaScript objects represent things that the JavaScript language needs to create a model of. For example, there is an object that deals only with dates and times.