Head First Architecture Chapter-4
In this chapter we discuss the logical components and how we would come up with them.
The book suggests following the below flow chart to devise the logical components:
Step 1 : Identifying initial core components:
this is purely a guessing game and most likely we refactor the components we come up with into others, so we should not spend a lot of time thinking of how big or small our components are.
this is purely a guessing game and most likely we refactor the components we come up with into others, so we should not spend a lot of time thinking of how big or small our components are.
The chapter shows two common approaches to get to the core components:
1- Work flow approach:
By thinking about the major workflow of the system,or the journey the user might take through the system.
2- Actor/Action approach:
This is particularly if you have multiple users in the system.First we start by identifying the various actors , then identify the primary actions they might take and assign each action to a new or existing component.
Th chapter then advises against having vague names for the components especially those with names like manager , controller or supervisor, as these would end up making the component do a lot of things instead of limited particular functions.
This is particularly if you have multiple users in the system.First we start by identifying the various actors , then identify the primary actions they might take and assign each action to a new or existing component.
Th chapter then advises against having vague names for the components especially those with names like manager , controller or supervisor, as these would end up making the component do a lot of things instead of limited particular functions.
The Chapter then went on going thru each of the 4 steps giving examples , the main takeaways are:
1- this is an iterative process , for example if when we are assigning requirements to the initial components found that , some components have more requirements than it should be we can create a new component and re-assign some of the requirements to it , same also goes for the responsibilities and roles .
2- We can measure coupling between components by measuring the afferent and efferent coupling of each component, its total coupling is the sum of it efferent coupling and afferent coupling.
a- Afferent coupling : sometimes called fan-in or incoming is like how parents are afferently coupled to their children and to the family dog, as the children are dependent on their parent to provide for them the care , food and allowance to buy candy or anything they need.so we say that parent are afferently coupled to their children.
b- efferent coupling : sometimes called fan-out or outgoing is when a component is dependent on other component or like the example of children and their parents but from the children's view they are dependent on their parents, so we say the child is efferently coupled to his parents and his teacher,...etc.
Law of Demeter:
this is also known as the principle of least knowledge, it is named after the greek goddess of agriculture where she provide all crops and grains to the mortals but she does not know what are the mortals doing with them, so she is loosely coupled to the mortal world.
1- this is an iterative process , for example if when we are assigning requirements to the initial components found that , some components have more requirements than it should be we can create a new component and re-assign some of the requirements to it , same also goes for the responsibilities and roles .
2- We can measure coupling between components by measuring the afferent and efferent coupling of each component, its total coupling is the sum of it efferent coupling and afferent coupling.
a- Afferent coupling : sometimes called fan-in or incoming is like how parents are afferently coupled to their children and to the family dog, as the children are dependent on their parent to provide for them the care , food and allowance to buy candy or anything they need.so we say that parent are afferently coupled to their children.
b- efferent coupling : sometimes called fan-out or outgoing is when a component is dependent on other component or like the example of children and their parents but from the children's view they are dependent on their parents, so we say the child is efferently coupled to his parents and his teacher,...etc.
Law of Demeter:
this is also known as the principle of least knowledge, it is named after the greek goddess of agriculture where she provide all crops and grains to the mortals but she does not know what are the mortals doing with them, so she is loosely coupled to the mortal world.
same can be applied also to logical components the more a component knows about other components , the more coupled it become to these components , so by reducing the knowledge of other components we reduce the coupling of this component to others.
Let's see an example of it in action , whereas the image below shows an ordering system:
Let's see an example of it in action , whereas the image below shows an ordering system:
in the figure above the order placement component is tightly coupled to other components , it also has so much knowledge about the order placement process and the coupling is balanced across the system.
By applying the law of demeter by decreasing the amount of knowledge that the order-placement component has about the process we can have a more loosely coupled system, see the image below:
so by offloading the actions to be taken in case of low-stock to the inventory management component we reduced the knowledge about the system and hence the coupling of the order placement component.By applying the law of demeter by decreasing the amount of knowledge that the order-placement component has about the process we can have a more loosely coupled system, see the image below:
Please note that we have increase the knowledge of the system for the Inventory-Management component



Comments
Post a Comment