Sunday, September 1, 2019

Evolution of Event Sourced Enterprise Applications

Sync. Methods are one way to update the State of Domain Model in the DB. Fire and Wait, Complex Error Recovery, Locking, Slow, No Change Log is stored. Response Code is fixed, To change Response Code we need to Change the Application.
If error recover fails, DB can go in inconsistent state.

Async. Methods are another way to do so. Fire and Forget, Simple Error Recovery, Response Code will be done in Handler, No Locking, Fast, No Change Log is stored. Response Code is fixed, To change Response Code we need to Change the Application.
If error recover fails, DB can go in inconsistent state.

Simple Domain Events are extensions to the Async. Methods in a very neat clean way. Fire and Forget, Simple Error Recovery, Response Code will be done in Handler, No Locking, Fast, No Change Log is stored. Response Code is dynamic and can be changed at run time or deployment time. Response code can be configured at deployment time. No need to change the application code.If error recover fails, DB can go in inconsistent state.

Domain Events with Event Sourcing are extensions to the Simple Domain Events in a very neat clean way. Fire and Forget, Simple Error Recovery, Response Code will be done in Handler, No Locking, Fast, Change Log is stored. Response Code is dynamic and can be changed at run time or deployment time. Response code can be configured at deployment time. No need to change the application code.If error recover fails, 
Less chances that DB can go in inconsistent state because we have Event Logs, Event Queue, Event processor.

Domain Events Martin Fowler

Domain Event

Captures the memory of something interesting which affects the domain
Captures interesting events in the domain that cause multiple reactions and those multiple reactions are unknown or may change over the period of time.

Many things happen in the Domain, Many Transactins and Domain Model State Changes occur in the Domain Model/DB. 
But we have to analyze, this Change to the DM state is significant, this may cause other actions to provoke. 

Silent Domain Model Changes
Reactive Domain Model Changes.

There are two extremes to which Domain Events can be used.

Without Event Sourcing
======================
We just need Events and Event Processing Queues. We log Events just to process them. We do not store the Events themselves.

With Event Sourcing
==========================
We use Domain Events, Event Logs, Event Processing all is there.
But additionally, we save those events as well.

Why We Need Event Sourcing.
================================
Normally we just apply the change to the Database. 
We just update the database with new state. 
We do not save the Change Set. 
Drawback is we cannot revert back to any initial position.
We cannot analyze the Recent Change Set happened inside the system.
We cannot do the AI, Predictions, Data Analysis, Trends.
We must save both Changes and the Final State of the DB.

Sync. Methods are one way to update the State of Domain Model in the DB. Fire and Wait, Complex Error Recovery, Locking, Slow, No Change Log is stored. Response Code is fixed, To change Response Code we need to Change the Application.
If error recover fails, DB can go in inconsistent state.

Async. Methods are another way to do so. Fire and Forget, Simple Error Recovery, Response Code will be done in Handler, No Locking, Fast, No Change Log is stored. Response Code is fixed, To change Response Code we need to Change the Application.
If error recover fails, DB can go in inconsistent state.

Simple Domain Events are extensions to the Async. Methods in a very neat clean way. Fire and Forget, Simple Error Recovery, Response Code will be done in Handler, No Locking, Fast, No Change Log is stored. Response Code is dynamic and can be changed at run time or deployment time. Response code can be configured at deployment time. No need to change the application code.If error recover fails, DB can go in inconsistent state.

Domain Events with Event Sourcing are extensions to the Simple Domain Events in a very neat clean way. Fire and Forget, Simple Error Recovery, Response Code will be done in Handler, No Locking, Fast, Change Log is stored. Response Code is dynamic and can be changed at run time or deployment time. Response code can be configured at deployment time. No need to change the application code.If error recover fails, 
Less chances that DB can go in inconsistent state because we have Event Logs, Event Queue, Event processor.

==================================



Subject is Entity or Aggregate Root whose state is going to be changed in response of Event being raised.

It could be the Entity or Aggregate Root whose State Change is to be modeled as Event

One Event is related to one Subject ????
One Subject can have many Events True
One Event has One Event Type ?????
One Event Type is related to many Events????

Event is the Use Case or Transaction or Requirement level thing or Verb that happens in the system. It corresponds to the Method in programming. It is a big concept. One Method Call could result in multiple method calls and multiple DB updates. In the same way One Event can cause multiple Event Types and multiple DB updates or work.

Event Response code could contain any thing.
Direct DB update
Send Email
Send Notification
Log the Event
Call another Web API Service that cause update DB, Email, Notification

In case of Web Application these events are done in the momentous object graphs.

Event Type ?????? 

I go to Babur's for a meal on Tuesday, and pay by credit card. 
Make payment by the Credit Card is a use case that effects the state of Domain Model in DB and we might be interested to propagate that as an event and we want to do multiple things in the response. 
An important transaction in the business and many stakeholders are affected by this. There could be events in the system those are less importannt and have very small impact on the system. 

High Impact Events/Use Cases are modeled as Domain Event

This might be modeled as an event, UC or Requiremnt
event type is 'make purchase' or Class that Model the Event/Data
whose subject is my credit card, Entity affected by Event in DB
and whose occurred date is Tuesday. 

If Babur's uses an old manual system and doesn't transmit the transaction until Friday, the noticed date would be Friday.

Things happen. Not all of them are interesting, 
UC happen some are low impact and other are high impact and important

some may be worth recording but don't provoke a reaction. 
Some events are need to be stored in event sotre but no reaction code is there.

Some events are needed ot be recorded in DB but does not cause great Reaction Code, Reaction Scope is limited. 

The most interesting ones cause a reaction. Many systems need to react to interesting events. 
High Impact Use Cases are done as Domain Event. These Events are recorded and as well as there is Reaction Code against the Events.

Often you need to know why a system reacts in the way it did.
Why we need to model such UC as the Events

Rather than simple Methods Calls or Async Method Calls, these UC are modeled as Events. This approach has many advantages.
Events those cause changes can be stored as well. We and go back to any previous state of the DB, and analyze when this bad thing has happened. 

It is like the Code First Migrations of EF. All Change Set is saved. All Schema Changes are kept as migrations. 
We have our final state of the DB SChema as well. We can revert Db Schema to any previous state. 

Same is the case with the Version Control Software. Final State of Code bases. Changes to the Code bases. Revert Code base to previous state. 

By funneling inputs to a system into streams of Domain Event you can keep a record of all the inputs to a system. 

keep the record of all Events/Method Calls to the System
kepp record of all Method Calls those case update DB and also save the parameters.
Method Call == Event 
Method Parameters == Event Type/ Event Data Container

This helps you organize your processing logic, and also allows you to keep an audit log of the inputs to the system.

How it Works

The essence of a Domain Event is that you use it to capture IMPORTANT & INTERESTING things / Use Cases/ Events/ that can trigger a change to the state of the application you are developing. THERE ARE MANY STATED HOLDERS THOSE ARE INTERESTED IN THAT IMPORTANT STATE CHANGE. 
These event objects are then processed to cause changes to the system, and stored to provide an Audit Log.
EVENT LOG == EVENT STORE
EVENTS ARE ALSO STORED FOR AUDIT LOG AND TRAILING
EVENT PROCESSOR == COMPONENT THAT ANALYSE AND PROCESS THSE EVENTS AND CAUSE THE STATE CHANGE IN THE DB
YOU CAN IMAGINE THAT ARE SAVE THE METHOD CALLS WITH PARAMETERS IN A QUEUE, THEN A EVENT PROCESS PROCESSES THESE METHOD CALLS AND DO THAT INTEDED THINGS.

Figure 1: Events funnel inputs into a single source.
Figure 1 helps illustrate the point. 
Here we have a system with inputs from a 
  • user interface, 
  • messaging system, and 
  • some direct manipulation of database tables. 

In order to resolve these to Domain Event we have components that interact with each of these input streams and convert the inputs into a stream of Domain Event which are stored in a EVENT OR persistent log. 
DATA INPUT STREAMS ===> PROCESSING COMP ==> DOM. EVENT STREAMS  ==> EVENT LOG/QUEUE ==> EVENT PROCESSOR
DATA INPUT STREAMS PROCESSOR THAT CONVERTS DATA INTO EVENTS
EVENT PROCESSOR THAT PROCESS THE DOMAIN EVENTS AND UPDATE THE STATE OF DB OR DO THE OTHER REACTIVE THINGS.
An event processor then reads the events from the log and processes them triggering our application to do whatever it's supposed to do.

TWO PROCESSING LAYERS. 
IST PROCESSING LAYER ==> CREATE AND LOG EVENTS
2ND PROCESSING LAYER ==> PROCESS THE EVENT

AS EVENTS ARE ONLY KNOWN THE ASPPLICATION, THERE FOR SENDING APPLICATION CANNOT SEND EVENTS DIRECTLY TO THE EVENT LOG. WE NEED MIDDLE COMPONENT. 

In this stream the first input layer of the system takes no action to the stimulus/INPUT STREAM other than to create and log an DOMAIN event. 

The second layer can then be ignorant of the actual input source, it just reacts to the event and processes it. PROCESS WHAT EVER IS THERE IN THE EVENT QUEUE. 

For this example I've shown just the one event log. 
In practice it often makes sense to separate the logs if the events have different response requirements. 
DIFFERNET TYPES OF EVENTS HAVE DIFF TYPES OR RESPONSE. IF THE RESPONSE IS DIFFERNET, WE NEED TO LOG IT ON THE DIFFERNET EVENT LOG/EVENT PROCESSOR.
ONE TYPE OF EVENT LOG IS RELATED TO ONE TYPE OF EVENT PROCESSOR AND CAN GENERATE RESPONSE TO ONE TYPE. 

ONE EVENT LOG FOR DB OPERATIONS
ONE EVENT LOG FOR EMAILS
ONE EVENT LOG FOR NOTIFICATIONS
ONE EVENT LOG FOR CALLING MESSAGING SYSTEMS

THEY MAY ALSO BE CATEGORIZED BY WHAT TYPE OF SOURCE IS SENDING THE INPUT STREAM.

UI GENERATED INPUT STREAM TO ONE EVENT LOG
MESSAGING SYSTEM INPUT TO ANOTHER EVENT LOG
DIRECT DB SERVER INPUT TO ANOTHER EVENT LOG

A user interface will typically want a much faster response time than many remote messaging systems, so it makes sense to 
put user interface traffic into a different log and use a separate processor for them. OR WE DO NOT USE LOG AT ALL.

SEPARATE EVENT LOG/PROCESS FOR INPUT STREAMS COMING FORM UI
SEPARATE EVENT LOG/PROCESS FOR INPUT STREAMS COMING FORM MESSAGING SYSTEM
SEPARATE EVENT LOG/PROCESS FOR INPUT STREAMS COMING FORM SEPEARTE DB SERVER

The diagram implies an asynchronous pipes and filters style of interaction, but this isn't an essential part of the approach. 
EVENT LOG CAN BE OPTIONAL IN CASE OF UI INTERACTION

IT COULD BE THE  asynchronous pipes and filters style of interaction,

OR IT COULD BE THE SYNC. COMMUNICATIONS

Indeed a common approach, particularly with user interface stimuli, is to have the UI handler invoke the event processor directly in a synchronous interaction WITHOUT HAVING EVENT LOG IN IT. SO IN CASE OF UI, AS WE NEED QUICK RESPONSE, THRE IS NOT EVENT LOG PART. EVENT GOES DIRECTLY TO THE EVENT PROCESSOR AND WE GET THE RESULT

Each Domain Event captures information from the external stimulus. Since this is logged and we want to use the log as an audit trail, it's important that this source data is immutable. That is once you've created the event object this source data cannot be changed.

DATA THAT IS SENT FORM EXT SOURCE CAN BE CHANGED ONCE IT IS STORED IN THE EVENT LOG AND EVENT OBJECT IS CREATED. 

However there is also another kind of data on the event that 
records what a system has done with SOURCE DATA - 
I call this the processing data
I characterize the data on a Domain Event as immutable source data that captures what the event is about 
and mutable processing data that records 
what the system does in response to it. 

Source data on a credit card charge would include how much the charge was for, who the vendor was, etc. THIS INFO SHOULD NOT BE CHANGED. HOW MUCH CHARGE, WHO THE VENDOR WAS.

Processing data might include which statement it appeared on. ?????????? STATEMENT MAY INCLUDE THE INFORMATION THAT HOW MUCH CHARGE, WHO THE VENDOR WAS.

If your PROGRAMMING platform has particular support for immutable objects it may be worth splitting the event into two objects to take advantage of this.
Although the source data can never change, it may be that the system needs to handle a change - typically because the original event was incorrect. ORIGINAL EVENT WAS ERRONEOUS.

You can handle this by receiving this change as a separate Retroactive Event. The processor then handles the retroactive event to correct the DATABASE consequences of the earlier erroneous event. REVERSE THE EFFECTS OF THE ERRORNEOUSE EVENT. 
Often this processing can be done at a very generic level.????????
A third, but only occasional, category of event data is 
cached data from derivations from other data on the event stream. ??????????

In these cases the event processor summarizes information from past events while processing the current event and 
adds that summarized data to the current event to speed up future processing. 

Like any cache, it's important to signal the fact that this data is free to be removed and recalculated should any adjustments occur.?????????
Different events occur for different reasons, so it's common to use different types of events. The event processor will then use the event type as part of its dispatch mechanism. The type of event can be represented by using sub types of events, or a 
separate event type object, or a mixture of both.
It's quite common that different types of event carry different data, so using sub types of event for the event types fits in well with that. The problem with sub types is that this leads to a proliferation of types, that is particularly frustrating if much of the data is the same. A hybrid approach uses sub types to handle different data and event type objects to signal dispatching.
Events are about something happening at a point in time, so it's natural for events to contain time information. 

When doing this it's important to consider two Time Point that could be stored with the event: 
the time the event occurred in the world and 
the time the event was noticed . 

These Time Points correspond to the notions of actual and record time.

Actual Time of Event
Time when the event was noticed by the system
Of course you don't always need both Time Points, but you should always consider whether you need both. 

The danger is picking one Time Point, and not being clear which Time Point you picked, either at the time or later. 

So I also suggest you name the Time Point clearly to indicate which one it is.
It's possible you may need multiple record Time Points to record when the event was noticed by various different systems.

When to Use It


Capturing system stimuli through Domain Event is a significant decision. 

It imposes a distinct architectural style on an application and a programming model that will often seem awkward - at least initially. 

At this point it's not clear whether this approach actually is any more effort once you've got used to it.
Despite its unusual nature, I see some significant benefits for using this approach.
The Audit Log of events provides a full record that is valuable both for audit and debugging purposes. 

If the system gets into a strange state you have a full log of the inputs that got it there. 

By storing the events that were actually processed 
you decrease the chances of 
neglecting to write important information to the Audit Log.
Clear event streams make it easier for other system to replace some or all of an application in the future by adding a Message Router to divert events to a new system. ????????????????

Although it isn't fashionable to design a system in a way that facilitates its eventual demise, the sheer frequency of system replacement projects should mean we ought to pay more attention to it.
Domain Event is particularly important as a necessary pattern for Event Sourcing, which organizes a system so that 
all updates are made through Domain Event.

Tuesday, May 28, 2019

Entity Ttypes Strong vs Weak Entities

Strong Entities:
If an entity can exist apart from all of its related entities (it is existence-independent), then that entity is referred to as a strong entity or regular entity. For example, suppose that the XYZ Corporation uses parts to produce its products. Furthermore, suppose that some of those parts are produced in-house and other parts are bought from vendors. In that scenario, it is quite possible for a PART to exist independently from a VENDOR in the relationship “PART is supplied by VENDOR,” because at least some of the parts are not supplied by a vendor. Therefore, PART is existence independent from VENDOR.

Weak Entities:

A weak entity is one that meets two conditions:
1. The entity is existence-dependent; that is, it cannot exist without the entity with which it has a relationship.
2. The entity has a primary key that is partially or totally derived from the parent entity in the relationship.
For example, a company insurance policy insures an employee and his/her dependents. For the purpose of describing an insurance policy, an EMPLOYEE might or might not have a DEPENDENT, but the DEPENDENT must be associated with an EMPLOYEE. Moreover, the DEPENDENT cannot exist without the EMPLOYEE; that is, a person cannot get insurance coverage as a dependent unless s(he) happens to be a dependent of an employee. DEPENDENT is the weak entity in the relationship “EMPLOYEE has DEPENDENT.”
    The Chen notation in the following Figure identifies the weak entity by using a double-walled entity rectangle.
 Types of Entities_ Strong and Weak Entities




Associative (Composite) Entities:

The associative entity is used to implement a M:N relationship between two or more entities. This associative entity (also known as a composite or bridge entity) is composed of the primary keys of each of the entities to be connected. An example of such a bridge is shown in the following Figure. The Crow’s Foot notation does not identify the composite entity as such. Instead, the composite entity is identified by the solid relationship line between the parent and child entities, thereby indicating the presence of a strong (identifying) relationship.

Types of Entities_ associative entity
Note that the composite ENROLL entity in the above Figure is existence-dependent on the other two entities; the composition of the ENROLL entity is based on the primary keys of the entities that are connected by the composite entity. The composite entity may also contain additional attributes that play no role in the connective process. For example, although the entity must be composed of at least the STUDENT and CLASS primary keys, it may also include such additional attributes as grades, absences, and other data uniquely identified by the student’s  performance in a specific class.

Finally, keep in mind that the ENROLL table’s key (CLASS_CODE and STU_NUM) is composed entirely of the primary keys of the CLASS and STUDENT tables. Therefore, no null entries are possible in the ENROLL table’s key attributes.

Weak Entity Type and Identifying Relationship:
As discussed before, an entity type has a key attribute which uniquely identifies each entity in the entity set. But there exists some entity type for which key attribute can’t be defined. These are called Weak Entity type.
For example, A company may store the information of dependants (Parents, Children, Spouse) of an Employee. But the dependents don’t have existence without the employee. So Dependent will be weak entity type and Employee will be Identifying Entity type for Dependant.

A weak entity type is represented by a double rectangle. The participation of weak entity type is always total. The relationship between weak entity type and its identifying strong entity type is called identifying relationship and it is represented by double diamond.

Derived Attribute –
An attribute which can be derived from other attributes of the entity type is known as derived attribute. e.g.; Age (can be derived from DOB). In ER diagram, derived attribute is represented by dashed oval.
er6
Multivalued Attribute –
An attribute consisting more than one value for a given entity. For example, Phone_No (can be more than one for a given student). In ER diagram, multivalued attribute is represented by double oval.
pno

Composite Attribute –
An attribute composed of many other attribute is called as composite attribute. For example, Address attribute of student Entity type consists of Street, City, State, and Country. In ER diagram, composite attribute is represented by an oval comprising of ovals.
er22

Key Attribute –
The attribute which uniquely identifies each entity in the entity set is called key attribute.For example, Roll_No will be unique for each student. In ER diagram, key attribute is represented by an oval with underlying lines.rno

Attribute(s):
Attributes are the properties which define the entity type. For example, Roll_No, Name, DOB, Age, Address, Mobile_No are the attributes which defines entity type Student. In ER diagram, attribute is represented by an oval.
er2

DBMS | Anomalies in Relational Model

Anomalies
There are different types of anomalies which can occur in referencing and referenced relation which can be discussed as:
image
Insertion anomaly: If a tuple is inserted in referencing relation and referencing attribute value is not present in referenced attribute, it will not allow inserting in referencing relation. For Example, If we try to insert a record in STUDENT_COURSE with STUD_NO =7, it will not allow.
Deletion and Updation anomaly: If a tuple is deleted or updated from referenced relation and referenced attribute value is used by referencing attribute in referencing relation, it will not allow deleting the tuple from referenced relation. For Example, If we try to delete a record from STUDENT with STUD_NO =1, it will not allow. To avoid this, following can be used in query:
  • ON DELETE/UPDATE SET NULL: If a tuple is deleted or updated from referenced relation and referenced attribute value is used by referencing attribute in referencing relation, it will delete/update the tuple from referenced relation and set the value of referenced attribute to NULL.
  • ON DELETE/UPDATE CASCADE: If a tuple is deleted or updated from referenced relation and referenced attribute value is used by referencing attribute in referencing relation, it will delete/update the tuple from referenced relation and referencing relation as well.
This article is contributed by Sonal Tuteja. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Thursday, May 9, 2019

What is Entity in DDD

http://users.csc.calpoly.edu/~jdalbey/205/Lectures/HOWTO-ERD.html
https://it.toolbox.com/blogs/craigborysowich/understanding-entities-in-e-r-diagrams-020107
https://docs.oracle.com/cd/A97335_02/apps.102/bc4j/developing_bc_projects/bc_awhatisanentityattribute.htm

Many objects are not fundamentally defined by their attributes, but rather by a thread of continuity and identity.

an ER model can be used also in the specification of domain-specific ontologies.

An entity is a 
  • Person
  • Role
  • Property
  • Products
  • Organizations
  • Agreements
  • Abstractions
  • Place
  • Thing
  • Idea
  • Concept of Interest
  • Organization
  • Event

to the business or organization about which data is likely to be kept.  

identify the roles, events, locations, tangible things or concepts about which the end-users want to store data. 

A data entity is anything real or abstract about which we want to store data. 

Entity types fall into five classes: roles, events, locations, tangible things, or concepts. 

The best way to identify entities is to ask the system owners and users to identify things about which they would like to capture, store and produce information. 

Another source for identifying entities is to study the forms, files, and reports generated by the current system. E.g. a student registration form would refer to Student (a role), but also Course (an event), Instructor (a role), Advisor (a role), Room (a location), etc.

Identify Entities 

The entities in this system are Department, Employee, Supervisor and Project. One is tempted to make Company an entity, but it is a false entity because it has only one instance in this problem. True entities must have more than one instance. 
Entity
A data entity is anything real or abstract about which we want to store data.

Entity types fall into five classes: 
roles, 
events, 
locations, 
tangible things or 
concepts.

E.g. employee, payment, campus, book. Specific examples of an entity are called instances. E.g. the employee John Jones, Mary Smith's payment, etc. 


Look for the people, places, things, organizations, concepts, and events that an organization needs to capture, store, or retrieve information about.
For example, in a school environment possible entities might be Student, Instructor, and Class.
 Entity‑type refers to a generic class of things such as Company.  Entity is the short form of entity-type.
 Entity‑occurrence refers to specific instances or examples of a type.  For example, one occurrence of the entity Car is Chevrolet Cavalier.
 An entity usually has attributes (i.e., data elements) that further describe it.  Each attribute is a characteristic of the entity.  An entity must possess a set of one or more attributes that uniquely identify it (called a primary key).
The entities on an Entity-Relationship Diagram are represented by boxes (i.e., rectangles).  The name of the entity is placed inside the box.
Identifying Entities
Identifying entities is the first step in Data Modelling.  Start by gathering existing information about the organization.  Use documentation that describes the information and functions of the subject area being analyzed, and interview subject matter specialists (i.e., end-users).  Derive the preliminary entity-relationship diagram from the information gathered by identifying objects (i.e., entities) for which information is kept.  Entities are easy to find.  Look for the people, places, things, organizations, concepts, and events that an organization needs to capture, store, or retrieve information about.
Types of Entities
 Different types of entities are required to provide a complete and accurate representation of an organization's data and to enable the analyst to use the Entity-Relationship Diagram as a starting point for physical database design.  Types of entities include:
Fundamental, Attributive, Associative
·          Fundamental Entity Type where the entity is a base entity that depends on no other for its existence.  

A fundamental entity has a primary key that is independent of any other entity and is typically composed of a single attribute.  

Fundamental entities are real-world, tangible objects, such as, Employee, Customer, or Product.
·          Attributive Entity Type where the entity depends on another for its existence

For example, Employee Hobby depends on Employee. 

An attributive entity depends on another entity for parts of its primary key.  

It can result from breaking out a repeating group, the first rule of normalization, or from an optional attribute.
·          Associative where the entity describes a connection between two entities with an otherwise many-to-many relationship,

for example, assignment of Employee to Project (an Employee can be assigned to more than one Project and a Project can be assigned to more than one Employee).

If information exists about the relationship, this information is kept in an associative entity.

For example, the number of hours the Employee worked on a particular Project is an attribute of the relationship between Employee and Project, not of either Employee or Project.  An associative entity is uniquely identified by concatenating the primary keys of the two entities it connects.

·          Subtype/Supertype where one entity (the subtype) inherits the attributes of another entity (the supertype). 













A super type entity is used to represent two or more entities when they are viewed as the same entity by some other entities.  A sub type entity is an entity that is a special case or refined version of another entity.  Sub type entities are created when attributes or relationships apply to only some occurrences of an entity, the subset of occurrences to which the attributes or relationships apply are separated into entity sub types.  When an attribute applies only to some occurrences of an entity, the subset of occurrences to which it applies should be separated into entity sub types.  The common data elements are put in the super type entity and the specific data elements are placed with the sub type to which they apply.  For example, Employee (super type) may contain three sub types, Permanent Employee, Part-time Employee, and Temporary Employee.  All data elements of the super type must apply to all sub types.  Each sub type contains the same key as the super type.  Relationships between an entity super type and its sub types are always described as "is a."  For example, Employee is a Permanent Employee, Employee is a Part-time Employee.
Identifying Entity Super types/Sub types
Entity supertypes/subtypes involve classes of entities that are truly different, but at the same time, significantly similar.  When identifying supertypes/subtypes, look for:
·          entity types that have the same attributes,
·          entity types that participate in the same relationships,
·          occurrences of an entity that do not participate in all the relationships in which the entity type participates,
·          occurrences of an entity that do not have all the attributes that the entity type has.
Entities on a Data Flow Diagram
Entities will often become data stores on Data Flow Diagrams.  More than one entity may map into a data store.

CATEGORIES OF ENTITIES

There are three general categories of entities:

·          Physical entities are tangible and easily understood.  They generally fall into one of the following categories:
People with different attributes that a business want to save in its data base

People with different behaviors/operations that business want to perform by its application and change its attributes
·          people, for example, doctor, patient, employee, customer,

Attributes of Properties and Operations on the Properties
Attributes of Equipment and Operations on Equipment those change its attributes
Attributes of Buildings and Operations on Building those change its attributes
Attributes of Furniture and Operations on Furniture those change its attributes
Attributes of Fixtures and Operations on Fiextures those change its attributes
Attributes of Supplies and Operations on Supplies those change its attributes 
Business in intersed in both ATTRIBUTES and OPERATIONS related to that Entity
·          property, for example, equipment, land and buildings, furniture and fixtures, supplies,
·          products, such as goods and services.
Attributes and Operations on Products on which in Business in really interested
Attributges and Operations on Goods in which Business is really interested
Attributes and Operations on Services in which Business is really interested to Record and Perform
·          Conceptual entities are not tangible and are less easily understood.  They are often defined in terms of other entity-types.  They generally fall into one of the following categories:
·          organizations, for example, corporation, church, government,
·          agreements, for example, lease, warranty, mortgage,
·          abstractions, such as strategy and blueprint.
Event/State entities are typically incidents that happen and business is interested to store or record those events. 

They are very abstract and are often modeled in terms of other entity-types as an associative entity.  

Examples of events are 

  • purchase event has attributes and operations
  • negotiation event attributes and operations
  • service call event has attributes and operations
  • deposit event has attributes and operations

  • purchase incident
  • negotiation incident
  • service call incident
  • deposit incident
Examples of states are, these are life cycle states of different entities.
During its life cycle, Entities takes different states, these States themselves are 
captured as Entities. these are Usually LOV or List those are assigned to Entities.

  • ownership state of any plot
  • enrollment status of the student
  • employment status of any citizen
IMPOSTER ENTITIES
When an Entity is not an Entity
There are a number of things that may appear to be 
entities about which facts are kept, 
but which should not be defined as such.  These include:
·          processes,
·          calculations,
·          reports,
·          facts about entities.
Processes
Processes may actually perform actions on entities but are not, themselves, entities.  they become the part of Domain Model.

Examples are:
·          payroll deduction,
·          budgeting (an action on an organization unit).
Calculations
Calculations may become VO
Calculations are derived from the attributes of an entity.  Examples are:
·          inventory level,
·          average age,
·          net worth.
Reports
Reports present facts about one or more entities.  Examples are:
·          Project schedule,
·          Income statement.
Facts About Entities
Facts about entities describe characteristics of an entity and should be modeled as attributes.  Examples are:
·          telephone number,
·          date of hire.
RULES FOR DEFINING ENTITIES
Entities are things in an organization that are of interest to the business.  They generally correspond to people, places, things, events, concepts and organizations.
Name each entity using a noun in the singular form (e.g., Employee not Employees).  Use a word that is precise and clearly identifies the object.  When appropriate and needed to distinguish similar entities, use an adjective to further describe the noun (e.g., Permanent Employee, Temporary Employee).
Use a term that is familiar to the business or is commonly used in everyday language. 

Avoid the use of obscure terminology unless it is commonly used in the organization under analysis.
The entity name is representative of the characteristics or attributes of the entity.  

Take this into account when naming entities.  For example, use a term such as Inventory Item rather than Item.

What is Database Entity?

Database entity is a thing, person, place, unit, object or any item about which the data should be captured and stored in the form of properties, workflow and tables. 

While workflow and tables are optional for database entity, properties are required (because entity without properties is not an entity).









Entity workflow is a kind of an entity lifecycle which consists of states, transitions and reasons why entity transits from one state to another. For example, when users change the state of entity ‘Task’ from ‘In Progress’ to ‘Closed’ they can select one of the available reasons: ‘Completed’ or ‘Cancelled’.


An entity may be defined as a thing capable of an independent existence that can be uniquely identified. 

An entity is a thing that exists either physically or logically. 

An entity may be a physical object such as a house or a car (they exist physically), 

an event such as a house sale or a car service, 

or a concept such as a customer transaction or order (they exist logically—as a concept). 

Although the term entity is the one most commonly used, following Chen we should really distinguish between an entity and an entity-type. 

An entity-type is a category. An entity, strictly speaking, is an instance of a given entity-type. 

There are usually many instances of an entity-type. 

Because the term entity-type is somewhat cumbersome, most people tend to use the term entity as a synonym for this term

Entities can be thought of as nouns. Examples: a computer, an employee, a song, a mathematical theorem, etc.

A relationship captures how entities are related to one another. 

Relationships can be thought of as verbs, linking two or more nouns. 

Examples: an owns relationship between a company and a computer, a supervises relationship between an employee and a department, a performs relationship between an artist and a song, a proves relationship between a mathematician and a conjecture, etc.

Entities and relationships can both have attributes. 

Examples: an employee entity might have a Social Security Number (SSN) attribute, while a proved relationship may have a date attribute.

Every entity (unless it is a weak entity) must have a minimal set of uniquely identifying attributes, which is called the entity's primary key.


Entity–relationship diagrams don't show single entities or single instances of relations. 

Rather, they show entity sets (all entities of the same entity type) and relationship sets (all relationships of the same relationship type). 

Examples: a particular song is an entity; the collection of all songs in a database is an entity set; the eatenrelationship between a child and her lunch is a single relationship; the set of all such child-lunch relationships in a database is a relationship set. In other words, a relationship set corresponds to a relation in mathematics, while a relationship corresponds to a member of the relation.