#466, #509: Added diagrams and Readme files

This commit is contained in:
nikhilbarar 2018-06-13 23:40:36 +05:30
parent d54e29051f
commit 71f61cd40e
6 changed files with 282 additions and 0 deletions

View File

@ -0,0 +1,25 @@
---
layout: pattern
title: Component Object
folder: component-object
permalink: /patterns/component-object/
categories: Testing
tags:
- Java
- Difficulty-Intermediate
---
## Intent
Web development is shifting more and more towards reusable components. Frameworks like React, Polymer, Angular etc. provide various component friendly abstractions to make front-end code-bases more maintainable. So our web applications are now full of “widgets” that have same behavior. We can use component various times on single web page or re-use it on various web pages. Therefore it is logical to create abstraction which covers functionality of single component and reuse it across end-to-end tests.
![alt text](./etc/component-object.png "Component Object Pattern")
## Applicability
Use the Component Object Pattern in the following situations:
* When you have various same components on single web page and you need to test the web page
* When you have multiple web pages using same component abstractions and you need to test the web pages
## Credits
* [Component Object](https://lkrnac.net/blog/2016/10/component-object-pattern-example/)

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

View File

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<class-diagram version="1.2.2" icons="true" automaticImage="PNG" always-add-relationships="false" generalizations="true"
realizations="true" associations="true" dependencies="false" nesting-relationships="true" router="FAN">
<class id="1" language="java" name="com.iluwatar.component.AddItemComponent" project="component-object"
file="/component-object/src/test/java/com/iluwatar/component/AddItemComponent.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="162" y="206"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="2" language="java" name="com.iluwatar.component.ItemsListComponent" project="component-object"
file="/component-object/src/test/java/com/iluwatar/component/ItemsListComponent.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="995" y="195"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="3" language="java" name="com.iluwatar.component.TodoPageObject" project="component-object"
file="/component-object/src/test/java/com/iluwatar/component/TodoPageObject.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="555" y="198"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<association id="4">
<end type="SOURCE" refId="3" navigable="false">
<attribute id="5" name="addTodoItemComponent"/>
<multiplicity id="6" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="1" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="7">
<end type="SOURCE" refId="3" navigable="false">
<attribute id="8" name="groceryItemsList"/>
<multiplicity id="9" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="2" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="10">
<end type="SOURCE" refId="3" navigable="false">
<attribute id="11" name="todoItemsList"/>
<multiplicity id="12" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="2" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="13">
<end type="SOURCE" refId="3" navigable="false">
<attribute id="14" name="addGroceryItemComponent"/>
<multiplicity id="15" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="1" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</classifier-display>
<association-display labels="true" multiplicity="true"/>
</class-diagram>

27
monitor-object/README.md Normal file
View File

@ -0,0 +1,27 @@
---
layout: pattern
title: Monitor Object
folder: monitor-object
permalink: /patterns/monitor-object/
categories: Concurrency
tags:
- Java
- Difficulty-Intermediate
---
## Intent
In 1974, Tony Hoare proposed the concept of monitors for designing and reasoning about objects that are shared between multiple threads. The key property of these "Hoare-style" monitors is that threads can wait until some specific assertion about the monitor's state is true and be guaranteed that it is still true after the thread has been awakened. The purpose of the Monitor Object is to provide an implementation of Hoare-style monitors for thread communication in a Java-based monitor package that automates assertion checking during execution. This approach reduces redundant coding and automates assertions checking during execution.
![alt text](./etc/monitor-object.png "Monitor Object Pattern")
## Applicability
Use the Monitor Object Pattern for thread signaling (over Java's wait() and notify() approach) in the following situations:
* When you need Defensive programming in multithreaded code - The monitor package provides support for defensive programming through the invariant() method and the assertion objects associated with each condition object. Java's notify() and wait() provide no assertion checking
* When you need objects to wait on multiple wait queues - The monitor package provides condition objects, each providing its own wait queue. Threads waiting for different assertions to become true wait on different queues. Using wait(), there is only one wait queue per object.
* When you need seamless passing of occupancy - In the monitor package, control is passed seamlessly from the signaling thread to an awaiting thread. You can be sure that, after returning from an await(), the assertion the thread has waited for is true. In contrast, the notify() and notifyAll() methods simply move a waiting thread back to the entry queue for the monitor.
## Credits
* [Theodore S. Norvell - Monitor Object](https://www.javaworld.com/article/2077769/core-java/better-monitors-for-java.html)
* [Monitor (syncronization)](https://en.wikipedia.org/wiki/Monitor_(synchronization))

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

View File

@ -0,0 +1,158 @@
<?xml version="1.0" encoding="UTF-8"?>
<class-diagram version="1.2.2" icons="true" automaticImage="PNG" always-add-relationships="false" generalizations="true"
realizations="true" associations="true" dependencies="false" nesting-relationships="true" router="FAN">
<class id="1" language="java" name="com.iluwatar.monitor.AbstractMonitor" project="monitor-object"
file="/monitor-object/src/main/java/com/iluwatar/monitor/AbstractMonitor.java" binary="false" corner="BOTTOM_RIGHT">
<position height="567" width="287" x="20" y="-114"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="2" language="java" name="com.iluwatar.monitor.Condition" project="monitor-object"
file="/monitor-object/src/main/java/com/iluwatar/monitor/Condition.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="839" y="263"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="3" language="java" name="com.iluwatar.monitor.Assertion" project="monitor-object"
file="/monitor-object/src/main/java/com/iluwatar/monitor/Assertion.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="824" y="669"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="4" language="java" name="com.iluwatar.monitor.Monitor" project="monitor-object"
file="/monitor-object/src/main/java/com/iluwatar/monitor/Monitor.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="155" y="668"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<interface id="5" language="java" name="com.iluwatar.monitor.MonitorListener" project="monitor-object"
file="/monitor-object/src/main/java/com/iluwatar/monitor/MonitorListener.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="674" y="-108"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</interface>
<class id="6" language="java" name="com.iluwatar.monitor.Semaphore" project="monitor-object"
file="/monitor-object/src/main/java/com/iluwatar/monitor/Semaphore.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="488" y="350"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="7" language="java" name="com.iluwatar.monitor.Semaphore.QueueElement" project="monitor-object"
file="/monitor-object/src/main/java/com/iluwatar/monitor/Semaphore.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="488" y="571"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="8" language="java" name="com.iluwatar.monitor.TrueAssertion" project="monitor-object"
file="/monitor-object/src/main/java/com/iluwatar/monitor/TrueAssertion.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="1063" y="670"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<association id="9">
<end type="SOURCE" refId="4" navigable="false">
<attribute id="10" name="invariant"/>
<multiplicity id="11" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="3" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="12">
<end type="SOURCE" refId="2" navigable="false">
<attribute id="13" name="homeMonitor"/>
<multiplicity id="14" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="1" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="15">
<end type="SOURCE" refId="8" navigable="false">
<attribute id="16" name="SINGLETON"/>
<multiplicity id="17" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="8" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="18">
<end type="SOURCE" refId="1" navigable="false">
<attribute id="19" name="entrance"/>
<multiplicity id="20" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="6" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<generalization id="21">
<end type="SOURCE" refId="4"/>
<end type="TARGET" refId="1"/>
</generalization>
<nesting id="22">
<end type="SOURCE" refId="6"/>
<end type="TARGET" refId="7"/>
</nesting>
<association id="23">
<end type="SOURCE" refId="6" navigable="false">
<attribute id="24" name="queue"/>
<multiplicity id="25" minimum="0" maximum="2147483647"/>
</end>
<end type="TARGET" refId="7" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="26">
<end type="SOURCE" refId="2" navigable="false">
<attribute id="27" name="queue"/>
<multiplicity id="28" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="6" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<generalization id="29">
<end type="SOURCE" refId="8"/>
<end type="TARGET" refId="3"/>
</generalization>
<association id="30">
<end type="SOURCE" refId="2" navigable="false">
<attribute id="31" name="assertion"/>
<multiplicity id="32" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="3" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="33">
<end type="SOURCE" refId="1" navigable="false">
<attribute id="34" name="listOfListeners"/>
<multiplicity id="35" minimum="0" maximum="2147483647"/>
</end>
<end type="TARGET" refId="5" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</classifier-display>
<association-display labels="true" multiplicity="true"/>
</class-diagram>