<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" >

<channel><title><![CDATA[From Passion to Profession - Notes]]></title><link><![CDATA[http://www.hsufengko.com/notes]]></link><description><![CDATA[Notes]]></description><pubDate>Tue, 17 Mar 2026 11:03:32 -0700</pubDate><generator>Weebly</generator><item><title><![CDATA[Temporal Collection]]></title><link><![CDATA[http://www.hsufengko.com/notes/temporal-collection]]></link><comments><![CDATA[http://www.hsufengko.com/notes/temporal-collection#comments]]></comments><pubDate>Mon, 25 May 2020 22:24:15 GMT</pubDate><category><![CDATA[Design Pattern]]></category><guid isPermaLink="false">http://www.hsufengko.com/notes/temporal-collection</guid><description><![CDATA[overview  A temporal collection is a simple way to implement a&nbsp;Temporal Property or a Temporal Object.&#8203;A temporal instance (either a Temporal Property or Temporal Object), when going through a series of amendments, the property itself or the properties the object references change&nbsp;over time. Each version of the temporal instance captures the state of the instance that will last for some period of time until the instance changes again with another amendment.&#8203;  implementation [...] ]]></description><content:encoded><![CDATA[<h2 class="wsite-content-title">overview</h2>  <div class="paragraph"><span>A temporal collection is a simple way to implement a&nbsp;Temporal Property or a Temporal Object.<br />&#8203;</span><br />A temporal instance (either a Temporal Property or Temporal Object), when going through a series of amendments, the property itself or the properties the object references change&nbsp;over time. Each version of the temporal instance captures the state of the instance that will last for some period of time until the instance changes again with another amendment.&#8203;<br /><br /></div>  <h2 class="wsite-content-title">implementation</h2>  <div class="paragraph"><strong>Temporal Collection<br /><br /></strong><span>The basic representation and interface for a temporal collection&nbsp;</span><span>provides get and put operations that use a date as an index:</span><br /></div>  <div id="731708656162109398"><div><style type="text/css">	#element-a16b2ed3-da85-48e8-9072-185b14ecc984 .code-editor--light {  padding: 20px 0px;}#element-a16b2ed3-da85-48e8-9072-185b14ecc984 .code-editor--light .header {  padding: 10px 20px;  font-weight: bold;  border-left: 1px solid #C9CDCF;  border-right: 1px solid #C9CDCF;  border-top: 1px solid #C9CDCF;  background-color: #F8F8F8;  color: #363B3E;}#element-a16b2ed3-da85-48e8-9072-185b14ecc984 .code-editor--light .header .paragraph {  margin: 0;}#element-a16b2ed3-da85-48e8-9072-185b14ecc984 .code-editor--light .body-code {  margin: 0;  border: 1px solid #C9CDCF;  background-color: #FFFFFF;  color: #666C70;}#element-a16b2ed3-da85-48e8-9072-185b14ecc984 .code-editor--dark {  padding: 20px 0px;}#element-a16b2ed3-da85-48e8-9072-185b14ecc984 .code-editor--dark .ace-tomorrow-night-eighties {  background-color: #363B3E;}#element-a16b2ed3-da85-48e8-9072-185b14ecc984 .code-editor--dark .header {  padding: 10px 20px;  font-weight: bold;  border-left: 1px solid #E0E1E2;  border-right: 1px solid #E0E1E2;  border-top: 1px solid #E0E1E2;  background-color: #666C70;  color: #FFFFFF;}#element-a16b2ed3-da85-48e8-9072-185b14ecc984 .code-editor--dark .header .paragraph {  margin: 0;}#element-a16b2ed3-da85-48e8-9072-185b14ecc984 .code-editor--dark .body-code {  margin: 0;  border: 1px solid #E0E1E2;  background-color: #363B3E;  color: #F8F8F8;}</style><div id="element-a16b2ed3-da85-48e8-9072-185b14ecc984" data-platform-element-id="270170748587580171-1.3.3" class="platform-element-contents">	<div class="code-editor--light">    <div class="header">        <div class="paragraph">TemporalCollection Interface</div>    </div>    <div class="body-code">        <pre class="editor"></pre>    </div></div></div><div style="clear:both;"></div></div></div>  <div>  <!--BLOG_SUMMARY_END--></div>  <div class="paragraph"><strong>Single Temporal Collection</strong><br /><br /><span>&#8203;The temporal collection implementation can use a&nbsp;</span><a href="http://www.hsufengko.com/notes/java-collection-framework">Map&lt;K,V&gt;</a>&nbsp;to keep track of the changes.<br /><br />A Single Temporal Collection is an implementation of Temporal Collection. A Single Temporal Collection keeps track of changes of an instance over time - over a single kind of time. That is, the updated time which is also the effective time.</div>  <div id="575385830701816811"><div><style type="text/css">	#element-c95265c4-39bf-48b7-8ab1-89b42ac4753a .code-editor--light {  padding: 20px 0px;}#element-c95265c4-39bf-48b7-8ab1-89b42ac4753a .code-editor--light .header {  padding: 10px 20px;  font-weight: bold;  border-left: 1px solid #C9CDCF;  border-right: 1px solid #C9CDCF;  border-top: 1px solid #C9CDCF;  background-color: #F8F8F8;  color: #363B3E;}#element-c95265c4-39bf-48b7-8ab1-89b42ac4753a .code-editor--light .header .paragraph {  margin: 0;}#element-c95265c4-39bf-48b7-8ab1-89b42ac4753a .code-editor--light .body-code {  margin: 0;  border: 1px solid #C9CDCF;  background-color: #FFFFFF;  color: #666C70;}#element-c95265c4-39bf-48b7-8ab1-89b42ac4753a .code-editor--dark {  padding: 20px 0px;}#element-c95265c4-39bf-48b7-8ab1-89b42ac4753a .code-editor--dark .ace-tomorrow-night-eighties {  background-color: #363B3E;}#element-c95265c4-39bf-48b7-8ab1-89b42ac4753a .code-editor--dark .header {  padding: 10px 20px;  font-weight: bold;  border-left: 1px solid #E0E1E2;  border-right: 1px solid #E0E1E2;  border-top: 1px solid #E0E1E2;  background-color: #666C70;  color: #FFFFFF;}#element-c95265c4-39bf-48b7-8ab1-89b42ac4753a .code-editor--dark .header .paragraph {  margin: 0;}#element-c95265c4-39bf-48b7-8ab1-89b42ac4753a .code-editor--dark .body-code {  margin: 0;  border: 1px solid #E0E1E2;  background-color: #363B3E;  color: #F8F8F8;}</style><div id="element-c95265c4-39bf-48b7-8ab1-89b42ac4753a" data-platform-element-id="270170748587580171-1.3.3" class="platform-element-contents">	<div class="code-editor--light">    <div class="header">        <div class="paragraph">SingleTemporalCollection Class</div>    </div>    <div class="body-code">        <pre class="editor"></pre>    </div></div></div><div style="clear:both;"></div></div></div>  <div class="paragraph">[1] Temporal Collection is backed by a private HashMap&lt;K,V&gt;.&nbsp;This HashMap contains the values indexed by the effective date (the date of when they become effective).<br />&#8203;[2]&nbsp;milestones() returns a List of keys (effective dates) <span>in a reverse order&nbsp;</span>from the MashMap.<br />&#8203;[3]&nbsp;get() works through these milestones to find the right key (effective date). This algorithm works best when you are more likely to ask for the most recent value.<br />[4] Sorts the specified&nbsp;list&nbsp;into reverse order. All elements in the&nbsp;list&nbsp;must implement the&nbsp;<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Comparable.html">Comparable</a>&nbsp;interface.</div>  <div class="paragraph"><strong>Bi-Temporal Collection</strong><br /><br /><span>A Bi-Temporal Collection is also an implementation of Temporal Collection. A Bi-Temporal Collection keeps track of changes of an instance over time. Two kinds of time are involved. That is, the updated time and the effective time of the change, both times can be different.</span></div>  <div id="182457927809335891"><div><style type="text/css">	#element-b8e90423-d24b-4d6c-97c9-265ac248b702 .code-editor--light {  padding: 20px 0px;}#element-b8e90423-d24b-4d6c-97c9-265ac248b702 .code-editor--light .header {  padding: 10px 20px;  font-weight: bold;  border-left: 1px solid #C9CDCF;  border-right: 1px solid #C9CDCF;  border-top: 1px solid #C9CDCF;  background-color: #F8F8F8;  color: #363B3E;}#element-b8e90423-d24b-4d6c-97c9-265ac248b702 .code-editor--light .header .paragraph {  margin: 0;}#element-b8e90423-d24b-4d6c-97c9-265ac248b702 .code-editor--light .body-code {  margin: 0;  border: 1px solid #C9CDCF;  background-color: #FFFFFF;  color: #666C70;}#element-b8e90423-d24b-4d6c-97c9-265ac248b702 .code-editor--dark {  padding: 20px 0px;}#element-b8e90423-d24b-4d6c-97c9-265ac248b702 .code-editor--dark .ace-tomorrow-night-eighties {  background-color: #363B3E;}#element-b8e90423-d24b-4d6c-97c9-265ac248b702 .code-editor--dark .header {  padding: 10px 20px;  font-weight: bold;  border-left: 1px solid #E0E1E2;  border-right: 1px solid #E0E1E2;  border-top: 1px solid #E0E1E2;  background-color: #666C70;  color: #FFFFFF;}#element-b8e90423-d24b-4d6c-97c9-265ac248b702 .code-editor--dark .header .paragraph {  margin: 0;}#element-b8e90423-d24b-4d6c-97c9-265ac248b702 .code-editor--dark .body-code {  margin: 0;  border: 1px solid #E0E1E2;  background-color: #363B3E;  color: #F8F8F8;}</style><div id="element-b8e90423-d24b-4d6c-97c9-265ac248b702" data-platform-element-id="270170748587580171-1.3.3" class="platform-element-contents">	<div class="code-editor--light">    <div class="header">        <div class="paragraph">BiTemporalCollection Class</div>    </div>    <div class="body-code">        <pre class="editor"></pre>    </div></div></div><div style="clear:both;"></div></div></div>  <h2 class="wsite-content-title">examples / usages</h2>  <div class="paragraph"><strong>Temporal Property vs. Temporal Object</strong><br /><br /><span>If you want the underlying implementation tracks the changes of an instance at the property level but not at the object level, implement Temporal Property.</span></div>  <div id="399328172687059173"><div><style type="text/css">	#element-dd072d89-667c-45ca-8c06-e2c54d1d748f .code-editor--light {  padding: 20px 0px;}#element-dd072d89-667c-45ca-8c06-e2c54d1d748f .code-editor--light .header {  padding: 10px 20px;  font-weight: bold;  border-left: 1px solid #C9CDCF;  border-right: 1px solid #C9CDCF;  border-top: 1px solid #C9CDCF;  background-color: #F8F8F8;  color: #363B3E;}#element-dd072d89-667c-45ca-8c06-e2c54d1d748f .code-editor--light .header .paragraph {  margin: 0;}#element-dd072d89-667c-45ca-8c06-e2c54d1d748f .code-editor--light .body-code {  margin: 0;  border: 1px solid #C9CDCF;  background-color: #FFFFFF;  color: #666C70;}#element-dd072d89-667c-45ca-8c06-e2c54d1d748f .code-editor--dark {  padding: 20px 0px;}#element-dd072d89-667c-45ca-8c06-e2c54d1d748f .code-editor--dark .ace-tomorrow-night-eighties {  background-color: #363B3E;}#element-dd072d89-667c-45ca-8c06-e2c54d1d748f .code-editor--dark .header {  padding: 10px 20px;  font-weight: bold;  border-left: 1px solid #E0E1E2;  border-right: 1px solid #E0E1E2;  border-top: 1px solid #E0E1E2;  background-color: #666C70;  color: #FFFFFF;}#element-dd072d89-667c-45ca-8c06-e2c54d1d748f .code-editor--dark .header .paragraph {  margin: 0;}#element-dd072d89-667c-45ca-8c06-e2c54d1d748f .code-editor--dark .body-code {  margin: 0;  border: 1px solid #E0E1E2;  background-color: #363B3E;  color: #F8F8F8;}</style><div id="element-dd072d89-667c-45ca-8c06-e2c54d1d748f" data-platform-element-id="270170748587580171-1.3.3" class="platform-element-contents">	<div class="code-editor--light">    <div class="header">        <div class="paragraph">Temporal Property</div>    </div>    <div class="body-code">        <pre class="editor"></pre>    </div></div></div><div style="clear:both;"></div></div></div>  <div class="paragraph"><span>[1] addresses is a Single Temporal Property</span><br /><span>[2] names is another Single Temporal Property<br />&#8203;</span><br /><span>On the other hand, if the changes&nbsp;at the object level&nbsp;</span><span>are to be stored in some sort of version history, implement Temporal Object.</span></div>  <div id="559471722245114431"><div><style type="text/css">	#element-b25d7e29-4921-46bb-b3fd-ddc0e327b8ba .code-editor--light {  padding: 20px 0px;}#element-b25d7e29-4921-46bb-b3fd-ddc0e327b8ba .code-editor--light .header {  padding: 10px 20px;  font-weight: bold;  border-left: 1px solid #C9CDCF;  border-right: 1px solid #C9CDCF;  border-top: 1px solid #C9CDCF;  background-color: #F8F8F8;  color: #363B3E;}#element-b25d7e29-4921-46bb-b3fd-ddc0e327b8ba .code-editor--light .header .paragraph {  margin: 0;}#element-b25d7e29-4921-46bb-b3fd-ddc0e327b8ba .code-editor--light .body-code {  margin: 0;  border: 1px solid #C9CDCF;  background-color: #FFFFFF;  color: #666C70;}#element-b25d7e29-4921-46bb-b3fd-ddc0e327b8ba .code-editor--dark {  padding: 20px 0px;}#element-b25d7e29-4921-46bb-b3fd-ddc0e327b8ba .code-editor--dark .ace-tomorrow-night-eighties {  background-color: #363B3E;}#element-b25d7e29-4921-46bb-b3fd-ddc0e327b8ba .code-editor--dark .header {  padding: 10px 20px;  font-weight: bold;  border-left: 1px solid #E0E1E2;  border-right: 1px solid #E0E1E2;  border-top: 1px solid #E0E1E2;  background-color: #666C70;  color: #FFFFFF;}#element-b25d7e29-4921-46bb-b3fd-ddc0e327b8ba .code-editor--dark .header .paragraph {  margin: 0;}#element-b25d7e29-4921-46bb-b3fd-ddc0e327b8ba .code-editor--dark .body-code {  margin: 0;  border: 1px solid #E0E1E2;  background-color: #363B3E;  color: #F8F8F8;}</style><div id="element-b25d7e29-4921-46bb-b3fd-ddc0e327b8ba" data-platform-element-id="270170748587580171-1.3.3" class="platform-element-contents">	<div class="code-editor--light">    <div class="header">        <div class="paragraph">Temporal Object</div>    </div>    <div class="body-code">        <pre class="editor"></pre>    </div></div></div><div style="clear:both;"></div></div></div>  <div class="paragraph"><span>[1] Temporal Collection is for storing version history of CustomerVersion<br />&#8203;<br />When a class has a few properties that has temporal behavior and you want access to those temporal values, use Temporal Property. Whereas, if most of the properties of the class are temporal, use Temporal Object.</span></div>  <h2 class="wsite-content-title">references</h2>  <div class="paragraph"><ul><li><a href="https://martinfowler.com/eaaDev/TemporalObject.html">Temporal Object</a></li><li><a href="https://martinfowler.com/eaaDev/TemporalProperty.html">Temporal Property</a>&#8203;</li><li><a href="https://howtodoinjava.com/sort/collections-sort/">Java &ndash; Collections sort() method</a></li><li><a href="https://github.com/JetBrains/MPS/tree/b6aee32fa26dd5c293dde899e0db86092bd9db02/samples/agreement/framework/source_gen/mf">Jetbrains / MPS</a>&#8203;&#8203;<br /></li></ul></div>]]></content:encoded></item><item><title><![CDATA[Data Transfer Object Design Pattern]]></title><link><![CDATA[http://www.hsufengko.com/notes/data-transfer-object-design-pattern]]></link><comments><![CDATA[http://www.hsufengko.com/notes/data-transfer-object-design-pattern#comments]]></comments><pubDate>Tue, 19 May 2020 07:56:05 GMT</pubDate><category><![CDATA[Design Pattern]]></category><guid isPermaLink="false">http://www.hsufengko.com/notes/data-transfer-object-design-pattern</guid><description><![CDATA[overview  Data Transfer Object (DTO) is an object used to pass data with multiple items in one shot between client and server, to avoid client from issuing multiple calls to a remote server to get each item in separate calls.Optionally, we can make use of a DTO Assembler class as some sort of a mapper in between DomainObject and DataTransferObject to map from one side to another in either direction. That is, to create a serializable DTO object given a Domain Object, or to update a Domain Object  [...] ]]></description><content:encoded><![CDATA[<h2 class="wsite-content-title">overview</h2>  <div class="paragraph"><span style="color:rgb(34, 34, 34)">Data Transfer Object (DTO) is an object used to pass data with multiple items in one shot between client and server, to avoid client from issuing multiple calls to a remote server to get each item in separate calls.</span><br /><br />Optionally, we can make use of a DTO Assembler class as some sort of a mapper in between DomainObject and DataTransferObject to map from one side to another in either direction. That is, to create a serializable DTO object given a Domain Object, or to update a Domain Object given a DTO object.</div>  <div><div class="wsite-image wsite-image-border-none " style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"> <a> <img src="http://www.hsufengko.com/uploads/8/0/5/7/8057674/dto_orig.jpg" alt="Picture" style="width:auto;max-width:100%" /> </a> <div style="display:block;font-size:90%"></div> </div></div>  <div>  <!--BLOG_SUMMARY_END--></div>  <h2 class="wsite-content-title">code example</h2>  <div id="742880925787393240"><div><style type="text/css">	#element-fb2c5965-cdfd-43c4-8e10-c0945748d1aa .code-editor--light {  padding: 20px 0px;}#element-fb2c5965-cdfd-43c4-8e10-c0945748d1aa .code-editor--light .header {  padding: 10px 20px;  font-weight: bold;  border-left: 1px solid #C9CDCF;  border-right: 1px solid #C9CDCF;  border-top: 1px solid #C9CDCF;  background-color: #F8F8F8;  color: #363B3E;}#element-fb2c5965-cdfd-43c4-8e10-c0945748d1aa .code-editor--light .header .paragraph {  margin: 0;}#element-fb2c5965-cdfd-43c4-8e10-c0945748d1aa .code-editor--light .body-code {  margin: 0;  border: 1px solid #C9CDCF;  background-color: #FFFFFF;  color: #666C70;}#element-fb2c5965-cdfd-43c4-8e10-c0945748d1aa .code-editor--dark {  padding: 20px 0px;}#element-fb2c5965-cdfd-43c4-8e10-c0945748d1aa .code-editor--dark .ace-tomorrow-night-eighties {  background-color: #363B3E;}#element-fb2c5965-cdfd-43c4-8e10-c0945748d1aa .code-editor--dark .header {  padding: 10px 20px;  font-weight: bold;  border-left: 1px solid #E0E1E2;  border-right: 1px solid #E0E1E2;  border-top: 1px solid #E0E1E2;  background-color: #666C70;  color: #FFFFFF;}#element-fb2c5965-cdfd-43c4-8e10-c0945748d1aa .code-editor--dark .header .paragraph {  margin: 0;}#element-fb2c5965-cdfd-43c4-8e10-c0945748d1aa .code-editor--dark .body-code {  margin: 0;  border: 1px solid #E0E1E2;  background-color: #363B3E;  color: #F8F8F8;}</style><div id="element-fb2c5965-cdfd-43c4-8e10-c0945748d1aa" data-platform-element-id="270170748587580171-1.3.3" class="platform-element-contents">	<div class="code-editor--dark">    <div class="header">        <div class="paragraph">Code Editor</div>    </div>    <div class="body-code">        <pre class="editor"></pre>    </div></div></div><div style="clear:both;"></div></div></div>  <h2 class="wsite-content-title">scenarios</h2>  <div class="paragraph">Use DTO pattern to:<ul><li><span style="color:rgb(36, 39, 41)">transfer data between processes/layers/objects</span>. (e.g. between&nbsp;javax.persistence.Entity and org.springframework.http.ResponseEntity)</li><li><span style="color:rgb(36, 39, 41)">&#8203;encapsulate parameters for method calls.&nbsp;</span></li></ul></div>]]></content:encoded></item><item><title><![CDATA[Inversion of Control / Dependency Injection Pattern]]></title><link><![CDATA[http://www.hsufengko.com/notes/inversion-of-control-dependency-injection-pattern]]></link><comments><![CDATA[http://www.hsufengko.com/notes/inversion-of-control-dependency-injection-pattern#comments]]></comments><pubDate>Fri, 20 Mar 2020 07:48:03 GMT</pubDate><category><![CDATA[Design Pattern]]></category><category><![CDATA[Java]]></category><category><![CDATA[Software Development]]></category><guid isPermaLink="false">http://www.hsufengko.com/notes/inversion-of-control-dependency-injection-pattern</guid><description><![CDATA[People who just&nbsp;started to learn Spring framework is often confused by the term "Inversion of Control" (IoC) which can be achieved through "Dependency Injection" (DI).DI is a way of providing the dependencies (e.g. creating objects and its dependencies), wiring components into application.&nbsp;In Spring, those objects defined and instantiated by Spring containers then inject into application are called Spring Beans.IoC&nbsp;is a concept, it means to create instances of dependencies first,  [...] ]]></description><content:encoded><![CDATA[<div class="paragraph">People who just&nbsp;<a href="https://spring.io/quickstart">started to learn Spring</a> framework is often confused by the term "<strong>Inversion of Control</strong>" (IoC) which can be achieved through "<strong>Dependency Injection</strong>" (DI).<br /><br /><strong>DI</strong> is a way of providing the dependencies (e.g. creating objects and its dependencies), wiring components into application.&nbsp;In Spring, those objects defined and instantiated by Spring containers then inject into application are called <strong>Spring Bean</strong>s.<br /><br /><strong>IoC</strong>&nbsp;is a concept, it means to create instances of dependencies first, the concept is usually achieved by using metadata-driven approach to assemble instances at runtime. IoC is the end result of DI. However,&nbsp;DI is not the only way to achieve IoC. For example, <a href="https://bizapps.wiki/index.php?title=XpressO#XpressO_in_Metadata-Driven_Development">Workday's XpressO</a> is a great example of metadata-driven development to achieve IoC.<br /><br />Here are some more good explanations:</div>  <div class="wsite-spacer" style="height:14px;"></div>  <blockquote><span style="color:rgb(36, 39, 41)">Inversion of Control (IoC) means to create instances of dependencies first and latter instance of a class (optionally injecting them through constructor), instead of creating an instance of the class first and then the class instance creating instances of dependencies. Thus, inversion of control&nbsp;</span><strong style="color:rgb(36, 39, 41)">inverts</strong><span style="color:rgb(36, 39, 41)">&nbsp;the&nbsp;</span><strong style="color:rgb(36, 39, 41)">flow of control</strong><span style="color:rgb(36, 39, 41)">&nbsp;of the program.&nbsp;</span><strong style="color:rgb(36, 39, 41)">Instead of</strong><span style="color:rgb(36, 39, 41)">&nbsp;the&nbsp;</span><strong style="color:rgb(36, 39, 41)">callee controlling</strong><span style="color:rgb(36, 39, 41)">&nbsp;the&nbsp;</span><strong style="color:rgb(36, 39, 41)">flow of control</strong><span style="color:rgb(36, 39, 41)">&nbsp;(while creating dependencies), the&nbsp;</span><strong style="color:rgb(36, 39, 41)">caller controls the flow of control of the program</strong><span style="color:rgb(36, 39, 41)">.<br /><br />&#8203;~</span><a href="https://stackoverflow.com/questions/3058/what-is-inversion-of-control">https://stackoverflow.com/questions/3058/what-is-inversion-of-control</a></blockquote>  <div class="wsite-spacer" style="height:17px;"></div>  <blockquote><span style="color:rgb(36, 39, 41)">IoC is a programming technique, expressed here in terms of object-oriented programming, in which <strong>object coupling is bound at run time by an assembler object and is typically not known at compile time</strong> using static analysis.<br /><br />&#8203;~</span><a href="http://en.wikipedia.org/wiki/Inversion_of_control">http://en.wikipedia.org/wiki/Inversion_of_control</a></blockquote>  <div class="wsite-spacer" style="height:25px;"></div>  <blockquote><span style="color:rgb(36, 39, 41)">IoC is a common pattern in the Java community that helps wire lightweight containers or assemble components from different projects into a cohesive application.<br />~</span><a href="http://www.martinfowler.com/articles/injection.html">http://www.martinfowler.com/articles/injection.html</a><span style="color:rgb(36, 39, 41)">&nbsp;</span><em style="color:rgb(36, 39, 41)">(reworded)</em></blockquote>  <div class="wsite-spacer" style="height:25px;"></div>  <blockquote>Spring helps in the creation of loosely coupled applications because of Dependency Injection.&nbsp;<br /><br />&#8203;In Spring, objects define their associations (dependencies) and do not worry about how they will get those dependencies. It is the responsibility of Spring to provide the required dependencies for creating objects.<br /><br />-<a href="https://stackoverflow.com/questions/9403155/what-is-dependency-injection-and-inversion-of-control-in-spring-framework">https://stackoverflow.com/questions/9403155/what-is-dependency-injection-and-inversion-of-control-in-spring-framework</a></blockquote>  <div>  <!--BLOG_SUMMARY_END--></div>  <div class="wsite-spacer" style="height:50px;"></div>  <h2 class="wsite-content-title">&#8203;references</h2>  <div class="paragraph"><ul><li><a href="https://stackoverflow.com/questions/3058/what-is-inversion-of-control">What is Inversion of Control?</a></li><li><a href="https://www.baeldung.com/inversion-control-and-dependency-injection-in-spring">Intro to Inversion of Control and Dependency Injection with Spring</a></li><li><a href="https://stackoverflow.com/questions/9403155/what-is-dependency-injection-and-inversion-of-control-in-spring-framework">What is Dependency Injection and Inversion of Control in Spring Framework?</a></li><li><a href="https://softwareengineering.stackexchange.com/questions/205681/why-is-inversion-of-control-named-that-way">Why is Inversion of Control named that way?</a></li><li><a href="https://www.martinfowler.com/articles/injection.html">Inversion of Control Containers and the Dependency Injection pattern</a></li><li><a href="https://www.baeldung.com/spring-bean">What is a Spring Bean?</a></li></ul></div>]]></content:encoded></item><item><title><![CDATA[Coin Change Problem]]></title><link><![CDATA[http://www.hsufengko.com/notes/coin-change-problem]]></link><comments><![CDATA[http://www.hsufengko.com/notes/coin-change-problem#comments]]></comments><pubDate>Wed, 04 Apr 2018 05:08:13 GMT</pubDate><category><![CDATA[Dynamic Programming]]></category><guid isPermaLink="false">http://www.hsufengko.com/notes/coin-change-problem</guid><description><![CDATA[Given coins of different denominations and a total amount of money, find the number of combinations that makes up that amount. &#8203;For example, given unlimited coins in 1, 2, 4 denominations, how many combinations are there to make up the amount of 12?  Thought Process  Given coins in different denominations, we'd solve this problem by breaking it into sub-problems which means given coins in less different denominations. The answer to the problem of given coins in n different denominations is [...] ]]></description><content:encoded><![CDATA[<div class="paragraph">Given coins of different denominations and a total amount of money, find the number of combinations that makes up that amount. &#8203;For example, given unlimited coins in 1, 2, 4 denominations, how many combinations are there to make up the amount of 12?</div>  <h2 class="wsite-content-title">Thought Process</h2>  <div class="paragraph">Given coins in different denominations, we'd solve this problem by breaking it into sub-problems which means given coins in less different denominations. The answer to the problem of given coins in n different denominations is based on solving the problem of given coins in (n-1) different denominations, and the answer to the problem of coins in (n-1) different denominations is based on solving the problem of coins in (n-2) different denominations.<br /><br />We can use an array named <em>combination</em>&nbsp;to store the number of combinations that make up the amount. For example, the number of combinations to make up the amount of 1 is stored&nbsp;<em>combination[1]</em>, and the combinations to make up the amount of 12 is stored in <em>combination [12]</em>.<br /><br />The number of combinations to make up a given amount is equal to the number of combinations before a coin denomination is added to the picture, plus the number of combinations after such a coin denomination is added to the picture for the amount of "amount - coin".&nbsp;<br /><br />When adding the first coin to the picture, we'd calculate this array - <em>combination</em>. When adding the 2nd coin to the picture, the same <em>combination[amount]</em> is being calculated based on the following pseudocode:&nbsp; &nbsp;</div>  <div id="937453821969148491"><div><style type="text/css">	#element-0edc38cb-d2eb-4f99-af81-dc8d0c240103 .code-editor--light {  padding: 20px 0px;}#element-0edc38cb-d2eb-4f99-af81-dc8d0c240103 .code-editor--light .header {  padding: 10px 20px;  font-weight: bold;  border-left: 1px solid #C9CDCF;  border-right: 1px solid #C9CDCF;  border-top: 1px solid #C9CDCF;  background-color: #F8F8F8;  color: #363B3E;}#element-0edc38cb-d2eb-4f99-af81-dc8d0c240103 .code-editor--light .header .paragraph {  margin: 0;}#element-0edc38cb-d2eb-4f99-af81-dc8d0c240103 .code-editor--light .body-code {  margin: 0;  border: 1px solid #C9CDCF;  background-color: #FFFFFF;  color: #666C70;}#element-0edc38cb-d2eb-4f99-af81-dc8d0c240103 .code-editor--dark {  padding: 20px 0px;}#element-0edc38cb-d2eb-4f99-af81-dc8d0c240103 .code-editor--dark .ace-tomorrow-night-eighties {  background-color: #363B3E;}#element-0edc38cb-d2eb-4f99-af81-dc8d0c240103 .code-editor--dark .header {  padding: 10px 20px;  font-weight: bold;  border-left: 1px solid #E0E1E2;  border-right: 1px solid #E0E1E2;  border-top: 1px solid #E0E1E2;  background-color: #666C70;  color: #FFFFFF;}#element-0edc38cb-d2eb-4f99-af81-dc8d0c240103 .code-editor--dark .header .paragraph {  margin: 0;}#element-0edc38cb-d2eb-4f99-af81-dc8d0c240103 .code-editor--dark .body-code {  margin: 0;  border: 1px solid #E0E1E2;  background-color: #363B3E;  color: #F8F8F8;}</style><div id="element-0edc38cb-d2eb-4f99-af81-dc8d0c240103" data-platform-element-id="270170748587580171-1.3.3" class="platform-element-contents">	<div class="code-editor--light">    <div class="header">        <div class="paragraph">Code Editor</div>    </div>    <div class="body-code">        <pre class="editor"></pre>    </div></div></div><div style="clear:both;"></div></div></div>  <div>  <!--BLOG_SUMMARY_END--></div>  <div class="wsite-spacer" style="height:50px;"></div>  <div class="paragraph">This video explains using the array very well:</div>  <div class="wsite-youtube" style="margin-bottom:10px;margin-top:10px;"><div class="wsite-youtube-wrapper wsite-youtube-size-auto wsite-youtube-align-center"> <div class="wsite-youtube-container">  <iframe src="//www.youtube.com/embed/jaNZ83Q3QGc?wmode=opaque" frameborder="0" allowfullscreen></iframe> </div> </div></div>  <div class="wsite-spacer" style="height:50px;"></div>  <h2 class="wsite-content-title">Code Sample</h2>  <div class="paragraph">Note the trick of initializing the combination[0] to 1 to begin with. [1]</div>  <div id="765878558203744867"><div><style type="text/css">	#element-bcf7da3d-b88b-4d05-86c3-ad6aa81993e5 .code-editor--light {  padding: 20px 0px;}#element-bcf7da3d-b88b-4d05-86c3-ad6aa81993e5 .code-editor--light .header {  padding: 10px 20px;  font-weight: bold;  border-left: 1px solid #C9CDCF;  border-right: 1px solid #C9CDCF;  border-top: 1px solid #C9CDCF;  background-color: #F8F8F8;  color: #363B3E;}#element-bcf7da3d-b88b-4d05-86c3-ad6aa81993e5 .code-editor--light .header .paragraph {  margin: 0;}#element-bcf7da3d-b88b-4d05-86c3-ad6aa81993e5 .code-editor--light .body-code {  margin: 0;  border: 1px solid #C9CDCF;  background-color: #FFFFFF;  color: #666C70;}#element-bcf7da3d-b88b-4d05-86c3-ad6aa81993e5 .code-editor--dark {  padding: 20px 0px;}#element-bcf7da3d-b88b-4d05-86c3-ad6aa81993e5 .code-editor--dark .ace-tomorrow-night-eighties {  background-color: #363B3E;}#element-bcf7da3d-b88b-4d05-86c3-ad6aa81993e5 .code-editor--dark .header {  padding: 10px 20px;  font-weight: bold;  border-left: 1px solid #E0E1E2;  border-right: 1px solid #E0E1E2;  border-top: 1px solid #E0E1E2;  background-color: #666C70;  color: #FFFFFF;}#element-bcf7da3d-b88b-4d05-86c3-ad6aa81993e5 .code-editor--dark .header .paragraph {  margin: 0;}#element-bcf7da3d-b88b-4d05-86c3-ad6aa81993e5 .code-editor--dark .body-code {  margin: 0;  border: 1px solid #E0E1E2;  background-color: #363B3E;  color: #F8F8F8;}</style><div id="element-bcf7da3d-b88b-4d05-86c3-ad6aa81993e5" data-platform-element-id="270170748587580171-1.3.3" class="platform-element-contents">	<div class="code-editor--light">    <div class="header">        <div class="paragraph"></div>    </div>    <div class="body-code">        <pre class="editor"></pre>    </div></div></div><div style="clear:both;"></div></div></div>  <div class="wsite-spacer" style="height:50px;"></div>  <h2 class="wsite-content-title">references</h2>  <div class="paragraph"><ul><li><a href="https://www.hackerrank.com/challenges/coin-change/problem">&#8203;The Coin Change Problem</a></li></ul></div>]]></content:encoded></item><item><title><![CDATA[Where Binary Heap is Used]]></title><link><![CDATA[http://www.hsufengko.com/notes/binary-heap-application]]></link><comments><![CDATA[http://www.hsufengko.com/notes/binary-heap-application#comments]]></comments><pubDate>Sat, 03 Mar 2018 02:03:05 GMT</pubDate><category><![CDATA[Data Structure]]></category><guid isPermaLink="false">http://www.hsufengko.com/notes/binary-heap-application</guid><description><![CDATA[definitions  A full binary tree (sometimes&nbsp;referred to as&nbsp;a&nbsp;proper binary tree&nbsp;or plane&nbsp;binary tree) is a tree in which every node other than the leaves has two children. In other words, each node has either 0 child or 2 children.&nbsp;A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.A perfect binary tree is a&nbsp;binary tree&nbsp;with all&nbsp;leaf&nbsp;nodes&nbsp;at  [...] ]]></description><content:encoded><![CDATA[<h2 class="wsite-content-title">definitions</h2>  <div class="paragraph">A <strong><em>full binary tree</em></strong> (sometimes&nbsp;referred to as&nbsp;a&nbsp;<strong><em>proper binary tree</em></strong>&nbsp;or <em><strong>plane&nbsp;binary tree</strong></em>) is a tree in which every node other than the leaves has two children. In other words, each node has either 0 child or 2 children.&nbsp;<br /><br />A <em><strong>complete binary tree</strong></em> is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.<br /><br />A <strong><em>perfect binary tree</em></strong> is a&nbsp;binary tree&nbsp;with all&nbsp;leaf&nbsp;nodes&nbsp;at the same&nbsp;depth. All&nbsp;internal nodes&nbsp;have&nbsp;degree&nbsp;2.</div>  <div><div class="wsite-multicol"><div class="wsite-multicol-table-wrap" style="margin:0 -15px;"> 	<table class="wsite-multicol-table"> 		<tbody class="wsite-multicol-tbody"> 			<tr class="wsite-multicol-tr"> 				<td class="wsite-multicol-col" style="width:50%; padding:0 15px;"> 					 						  <div><div class="wsite-image wsite-image-border-none " style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"> <a> <img src="http://www.hsufengko.com/uploads/8/0/5/7/8057674/764887408_orig.png" alt="Picture" style="width:auto;max-width:100%" /> </a> <div style="display:block;font-size:90%"></div> </div></div>   					 				</td>				<td class="wsite-multicol-col" style="width:50%; padding:0 15px;"> 					 						  <div><div class="wsite-image wsite-image-border-none " style="padding-top:10px;padding-bottom:10px;margin-left:0px;margin-right:0px;text-align:center"> <a> <img src="http://www.hsufengko.com/uploads/8/0/5/7/8057674/published/staticshot-02-03-2018-18-12-00.png?1520043175" alt="Picture" style="width:317;max-width:100%" /> </a> <div style="display:block;font-size:90%">Perfect Tree</div> </div></div>   					 				</td>			</tr> 		</tbody> 	</table> </div></div></div>  <div class="paragraph">A <em><strong>Binary Heap</strong></em> is a binary tree with following 2 properties:<br />&#8203;<ol><li>A complete tree.</li><li>A Min Heap or Max Heap.&nbsp;In a Min Binary Heap, the key at root must be minimum among all keys present in Binary Heap.&nbsp;The same property must be recursively true for all nodes in Binary Tree. Max Binary Heap is similar to Min Heap.</li></ol><br /><br /></div>  <div>  <!--BLOG_SUMMARY_END--></div>  <h2 class="wsite-content-title">implementation</h2>  <div class="paragraph"><span style="color:rgb(68, 68, 68)">A very efficient way to implement a max heap is by using an array. To find an object&rsquo;s children within the array we can use the formula:</span><br /><br /><em>leftChild = 2 * nodeIndex + 1<br />rightChild = 2 * nodeIndex + 2<br /><br />To build a Heap it takes O(n):</em><br /></div>  <blockquote>def build_heap(A[1...n]): <br />&nbsp;size &lt;- n <br />&nbsp;for i from n/2 downto 1: <br />&nbsp; siftDown(i)</blockquote>  <div class="paragraph"><span style="color:rgb(68, 68, 68)">There are 4 major methods for implementing a max heap:</span><br /><br />add()<br /><br /><span style="color:rgb(68, 68, 68)">When objects are first added to the heap they are initially added to the end of the heap (end of array).&nbsp;</span><br /><br />remove()<span style="color:rgb(68, 68, 68)">&nbsp;</span><br /><br /><span style="color:rgb(68, 68, 68)">Remove and return its largest object. The&nbsp;</span>remove()<span style="color:rgb(68, 68, 68)">&nbsp;method removes the root object (or first object in the array), immediately replaced with the last object in the heap, followed by siftDown()</span><br /><br />siftUp()<br /><br /><span style="color:rgb(68, 68, 68)">The&nbsp;</span>siftUp()<span style="color:rgb(68, 68, 68)">&nbsp;method is used to move a newly inserted object from the last position in the array to its final location.</span><br /><br />siftDown()<br />&#8203;<br /><span style="color:rgb(68, 68, 68)">The&nbsp;</span>siftDown()<span style="color:rgb(68, 68, 68)">&nbsp;method is used to move the newly added root object (or first object in the array) to its correct position.&nbsp;</span></div>  <h2 class="wsite-content-title">applications</h2>  <div class="paragraph"><ol><li><a href="http://quiz.geeksforgeeks.org/heap-sort/" target="_blank">Heap Sort</a>: Heap Sort uses Binary Heap to sort an array in O(nLogn) time.</li><li>Priority Queue: Priority queues can be efficiently implemented using Binary Heap because it supports insert(), delete() and extractmax(), decreaseKey() operations in O(logn) time.&nbsp;</li><li><a href="http://www.hsufengko.com/blog/dijkstras-algorithm">Dijkstra&rsquo;s Shortest Path</a>:&nbsp;Min Heap to store the vertices not yet included in Shortest Path Tree (the unsettled set, or the vertices for which shortest distance is not finalized yet). &nbsp;Min Heap is used as a priority queue to get the minimum distance vertex from set of not yet&nbsp;included&nbsp;vertices. Time complexity of operations like extract-min and decrease-key value is O(logn) for Min Heap.</li><li><a href="https://www.geeksforgeeks.org/greedy-algorithms-set-5-prims-minimum-spanning-tree-mst-2/" target="_blank">Prim&rsquo;s Minimum Spanning Tree</a></li><li><a href="https://www.geeksforgeeks.org/greedy-algorithms-set-5-prims-minimum-spanning-tree-mst-2/" target="_blank">&#8203;</a><a href="https://www.geeksforgeeks.org/k-largestor-smallest-elements-in-an-array/" target="_blank">K&rsquo;th Largest Element in an array</a>&nbsp;(partial sorting)</li><li><a href="https://www.geeksforgeeks.org/nearly-sorted-algorithm/" target="_blank">Sort an almost sorted array</a></li><li><a href="https://www.geeksforgeeks.org/merge-k-sorted-arrays/" target="_blank">Merge K Sorted Arrays</a></li></ol></div>  <h2 class="wsite-content-title">comparison</h2>  <div class="paragraph"><span><strong>Binary Heap vs. Binary Search Tree</strong><br /><br />By comparison, if a binary tree is sorted, items to the left of a particular node are smaller, items to the right are larger, then we call it&nbsp;</span><em><strong>Binary Search Tree</strong></em><span>. Binary Heap does not guarantees the order while Binary Search Tree does. A&nbsp;</span><strong><em>Balanced Binary Search Tree</em></strong><span>&nbsp;guarantees height of O(log n) for n items.&nbsp;</span><br /><br /><strong>Binary Heap vs. Red-Black Tree</strong><br /><br /><span style="color:rgb(51, 51, 51)">Red-Black tree is a&nbsp;</span><span style="color:rgb(34, 34, 34)">self-balancing binary search&nbsp;</span>tree<span style="color:rgb(51, 51, 51)">&nbsp;done by coloring each node in the tree with either red or black and preserving a set of properties that guarantee that the deepest path in the tree is not longer than twice the shortest one, while Binary Heap is a complete tree that guarantees the tree is balanced.&nbsp;</span><span style="color:rgb(51, 51, 51)"></span></div>  <h2 class="wsite-content-title">references</h2>  <div class="paragraph"><ul><li><a href="https://www.geeksforgeeks.org/applications-of-heap-data-structure/">&#8203;https://www.geeksforgeeks.org/applications-of-heap-data-structure/</a></li><li><a href="https://www.geeksforgeeks.org/binary-heap/">https://www.geeksforgeeks.org/binary-heap/</a>&#8203;</li><li><a href="https://www.geeksforgeeks.org/greedy-algorithms-set-7-dijkstras-algorithm-for-adjacency-list-representation/">https://www.geeksforgeeks.org/greedy-algorithms-set-7-dijkstras-algorithm-for-adjacency-list-representation/</a></li><li><a href="http://bigdatums.net/2016/07/28/create-max-heap-using-an-array-java/">http://bigdatums.net/2016/07/28/create-max-heap-using-an-array-java/</a></li><li><a href="https://towardsdatascience.com/course-2-data-structure-part-2-priority-queues-and-disjoint-set-ed11a0383011">https://towardsdatascience.com/course-2-data-structure-part-2-priority-queues-and-disjoint-set-ed11a0383011</a><br /></li><br /><br /><br /><br /><br /><br /><br /></ul></div>]]></content:encoded></item><item><title><![CDATA[Java 1.8 Lambda & Method Reference]]></title><link><![CDATA[http://www.hsufengko.com/notes/lambda-method-reference]]></link><comments><![CDATA[http://www.hsufengko.com/notes/lambda-method-reference#comments]]></comments><pubDate>Mon, 26 Feb 2018 06:19:16 GMT</pubDate><category><![CDATA[Concurrency]]></category><category><![CDATA[Functional Programming]]></category><category><![CDATA[Java]]></category><guid isPermaLink="false">http://www.hsufengko.com/notes/lambda-method-reference</guid><description><![CDATA[One way to create thread is to pass a object that implements Runnable Interface to a Thread constructor as mentioned in Java Multithreading Approaches (Java Concurrency - Part 1):  &#8203;public class MyRunnable&nbsp;implements Runnable{&nbsp; // this method is called when a runnable thread starts&nbsp;&nbsp;public void run(){&nbsp; &nbsp; printMessage();&nbsp; }}public class ThreadDemo{&nbsp; public static void main(String args[]){&nbsp; &nbsp;&nbsp;Thread t1 = new Thread(new MyRunnable);&nbsp; [...] ]]></description><content:encoded><![CDATA[<div class="paragraph">One way to create thread is to pass a object that implements Runnable Interface to a Thread constructor as mentioned in <a href="http://www.hsufengko.com/blog/java-multithreading-approaches">Java Multithreading Approaches (Java Concurrency - Part 1)</a>:</div>  <blockquote><em><span>&#8203;</span><span>public class MyRunnable&nbsp;</span><font color="#c23b3b">implements Runnable</font><span>{</span><br /><span>&nbsp; // this method is called when a runnable thread starts</span><br /><span>&nbsp;&nbsp;<font color="#c23b3b">public void run()</font>{</span><br /><span>&nbsp; &nbsp; printMessage();</span><br /><span>&nbsp; }</span><br /><span>}</span><br /><br /><span>public class ThreadDemo{</span><br /><span>&nbsp; public static void main(String args[]){</span><br /><span>&nbsp; &nbsp;</span><font color="#c23b3b">&nbsp;Thread t1 = new Thread(new MyRunnable);</font><span>&nbsp;</span><br /><span>&nbsp; &nbsp;&nbsp;Thread t2 = new Thread(new MyRunnable);<br />&nbsp; &nbsp; Thread t3 = new Thread(new MyRunnable);<br /><font color="#c23b3b">&nbsp; &nbsp; t1.start();&nbsp; &nbsp;&nbsp;</font><br />&nbsp; &nbsp; t2.start();<br />&nbsp; &nbsp; t3.start();</span><br /><span>&nbsp; }<br /><br />&nbsp; public static void printMessage(){<br />&nbsp; &nbsp; System.out.println("Hello");<br />&nbsp; }<br />}</span></em><br /></blockquote>  <div>  <!--BLOG_SUMMARY_END--></div>  <div class="paragraph">Java 1.8 introduce Functional Interface.&nbsp;<span>Any interface with a SAM (Single Abstract Method) is a functional interface, and its implementation may be written as a lambda expression.&nbsp;A Functional Interface can have many default methods or static methods declared, but can only have one single abstract method.&nbsp;</span><br /><br />You may use Lambda Expression in place of a Functional Interface. For example, Runnable interface is a Functional Interface. Let me use the Lambda Expression instead. In this approach, I no longer need to define MyRunnable.</div>  <blockquote><span>public <em>clas</em>s ThreadDemo{</span><br /><span>&nbsp; public static void main(String args[]){</span><br /><span>&nbsp; &nbsp;</span><font color="#c23b3b">&nbsp;Thread t1 = new Thread(() -&gt; printMessage());</font><span>&nbsp;</span><br />&nbsp; &nbsp;&nbsp;Thread t2 = new Thread(() -&gt; printMessage());<br />&nbsp; &nbsp; Thread t3 = new Thread(() -&gt; printMessage());<br /><span><font color="#c23b3b">&nbsp; &nbsp; t1.start();&nbsp; &nbsp;&nbsp;</font><br />&nbsp; &nbsp; t2.start();<br />&nbsp; &nbsp; t3.start();</span><br /><span>&nbsp; }<br /><br />&nbsp; public static void printMessage(){<br />&nbsp; &nbsp; System.out.println("Hello");<br />&nbsp; }<br />}</span></blockquote>  <div class="paragraph">A method reference is the shorthand/alternative syntax for a lambda expression that executes just ONE method. Replace,</div>  <blockquote>() -&gt; printMessage();</blockquote>  <div class="paragraph">with,</div>  <blockquote>ThreadDemo::printMessage</blockquote>  <div class="paragraph">and get:</div>  <blockquote><span>public class ThreadDemo{</span><br /><span>&nbsp; public static void main(String args[]){</span><br /><span>&nbsp; &nbsp;</span><font color="#c23b3b">&nbsp;Thread t1 = new Thread(ThreadDemo::printMessage);</font><span>&nbsp;</span><br />&nbsp; &nbsp;&nbsp;Thread t2 = new Thread(ThreadDemo::printMessage);<br />&nbsp; &nbsp; Thread t3 = new Thread(ThreadDemo::printMessage);<br /><span><font color="#c23b3b">&nbsp; &nbsp; t1.start();&nbsp; &nbsp;&nbsp;</font><br />&nbsp; &nbsp; t2.start();<br />&nbsp; &nbsp; t3.start();</span><br /><span>&nbsp; }<br /><br />&nbsp; public static void printMessage(){<br />&nbsp; &nbsp; System.out.println("Hello");<br />&nbsp; }<br />}</span></blockquote>  <div class="paragraph">To take the Method Reference syntax one step further, as another example, you can replace Lambda Expression:</div>  <blockquote>(p) -&gt; System.out.println(p)</blockquote>  <div class="paragraph">with,</div>  <blockquote>System.out::println</blockquote>  <div class="paragraph">as in:</div>  <blockquote>public class MethodReferenceExample{<br />&nbsp; public static void main(String[] args){<br />&nbsp; &nbsp; List&lt;Person&gt; people = Arrays.asList(<br />&nbsp; &nbsp; &nbsp; new Person("Charles", "Dickens", 60),<br />&nbsp; &nbsp; &nbsp; new Person(Lewis", "Carroll", 42)<br />&nbsp; &nbsp; );<br />&nbsp; &nbsp; performConditionally(people, p -&gt; true, System.out::println);<br />&nbsp; }<br /><br />&nbsp; private static void performConditionally(List&lt;Person&gt; people, Predicate&lt;Person&gt; predicate, Consumer&lt;Person&gt; consumer)<br />&nbsp; &nbsp; for (Person p: people){<br />&nbsp; &nbsp; &nbsp; if (predicate.test(p)){<br />&nbsp; &nbsp; &nbsp; &nbsp; consumer.accept(p);<br />&nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; }<br />}<br /></blockquote>]]></content:encoded></item><item><title><![CDATA[Technical Product Manager Skills]]></title><link><![CDATA[http://www.hsufengko.com/notes/product-manager-skills]]></link><comments><![CDATA[http://www.hsufengko.com/notes/product-manager-skills#comments]]></comments><pubDate>Thu, 28 Dec 2017 21:14:51 GMT</pubDate><category><![CDATA[Product Management]]></category><guid isPermaLink="false">http://www.hsufengko.com/notes/product-manager-skills</guid><description><![CDATA[A product manager&nbsp;does many things.&nbsp;A product manager is like a CEO with all responsibilities except any of the authority.Here's a list of skills that tech companies look for in product managers:Technical Skills - Coding level knowledge.&nbsp;Some companies prefer software development as a prerequisite for product managers, Some don't. A good technical understanding will never hurt&#8203;.&#8203;People Skills -&nbsp;Build communication and trust from your development team.Research Skil [...] ]]></description><content:encoded><![CDATA[<div class="paragraph"><span style="color:rgb(101, 101, 101)">A product manager&nbsp;<a href="http://www.hsufengko.com/home/what-is-software-product-manager">does many things.</a>&nbsp;A product manager is like a CEO with all responsibilities except any of the authority.<br /><br />Here's a list of skills that tech companies look for in product managers:</span><br /><br /><strong>Technical Skills - </strong>Coding level knowledge.&nbsp;<span style="color:rgb(101, 101, 101)">Some companies prefer software development as a prerequisite for product managers, Some don't. A good technical understanding will never hurt</span>&#8203;.<br /><br /><strong>&#8203;People Skills -&nbsp;</strong>Build communication and trust from your development team.<br /><br /><strong>Research Skills<br /><br />Management Skills</strong><br /><br /><strong>User-centricity</strong><br /><br /><strong>Data-driven Analytics - </strong>Use SQL, Excel, etc. to make data-driven decisions. Put<span style="color:rgb(48, 48, 48)">&nbsp;product investments in the areas that will produce the best return on investment.</span><br /><br /><strong>Strategic Thinking&nbsp;</strong>- Product go-to-market strategy. Game theory.<br /><br /><strong>Good Design-sense&nbsp;</strong>- Markup/wireframe.<br /><br /><strong>Experimentation Mindset -&nbsp;</strong>A/B testing.</div>  <div>  <!--BLOG_SUMMARY_END--></div>  <h2 class="wsite-content-title">References</h2>  <div class="paragraph"><ul><li><a href="https://www.toptal.com/product-managers/product-management#hiring-guide">A Comprehensive Guide to Hiring Product Managers</a></li><li><a href="https://hired.com/blog/candidates/skills-tech-companies-product-managers/">6 Skills Technical Companies Look for in Product Managers</a></li><li><a href="http://community.uservoice.com/blog/technical-skills-every-product-manager-should-know/">Top 5 Technical Skills Every Product Manager Should Have</a></li><li><a href="https://www.coursera.org/learn/game-theory-1">Game Theory</a></li></ul></div>]]></content:encoded></item><item><title><![CDATA[Sales Copy Framework]]></title><link><![CDATA[http://www.hsufengko.com/notes/sales-copy-framework]]></link><comments><![CDATA[http://www.hsufengko.com/notes/sales-copy-framework#comments]]></comments><pubDate>Mon, 13 Mar 2017 22:42:58 GMT</pubDate><category><![CDATA[Marketing]]></category><guid isPermaLink="false">http://www.hsufengko.com/notes/sales-copy-framework</guid><description><![CDATA[Copywriting&nbsp;is using words to get people to give up their money in exchange for services or products. In other words, it is&nbsp;&ldquo;salesmanship in print.&rdquo; as defined by&nbsp;John E. Kennedy back in 1904.The copywriting should be all about the consumers so the copywriter have to talk about them, talk about the problem, the promise, the proof, and the proposal to solve the problem. The copy must be useful and valuable. No copy is too long, too short, only too boring. Write about th [...] ]]></description><content:encoded><![CDATA[<div class="paragraph">Copywriting&nbsp;is using words to get people to give up their money in exchange for services or products. In other words, it is&nbsp;<span style="color:rgb(81, 81, 81)">&ldquo;salesmanship in print.&rdquo; as defined by&nbsp;<a href="https://adage.com/article/special-report-the-advertising-century/john-e-kennedy/140216">John E. Kennedy</a> back in 1904.</span><br /><br />The copywriting should be all about the consumers so the copywriter have to talk about them, talk about the problem, the promise, the proof, and the proposal to solve the problem. The copy must be useful and valuable. No copy is too long, too short, only too boring. Write about the preponderance of proof so the consumer have to make a decision.<br /><br />Here's a six-part framework (PASTOR)&nbsp;for writing better sales copy that <a href="http://rayedwards.com/">Ray Edwards</a> mentioned:<br /><br />P = person, problem, pain.<br />A = amplify the consequence of not solving the problem.<br />S = story, solution , system.<br />T = transformation, testimony<br />O = offer<br />&#8203;R = response</div>]]></content:encoded></item><item><title><![CDATA[Position Yourself for Products in Competitions]]></title><link><![CDATA[http://www.hsufengko.com/notes/position-yourself-in-competitions]]></link><comments><![CDATA[http://www.hsufengko.com/notes/position-yourself-in-competitions#comments]]></comments><pubDate>Tue, 08 Nov 2016 19:25:15 GMT</pubDate><category><![CDATA[Entrepreneur]]></category><category><![CDATA[Marketing]]></category><category><![CDATA[Product Management]]></category><guid isPermaLink="false">http://www.hsufengko.com/notes/position-yourself-in-competitions</guid><description><![CDATA[       You want to stand out when the competition is already there when entering a market. Think about three things:Form your own personality for your identity: Clone a service offer by a guru won't make you a guru. You want to have the content come out your personality, yourself. Clients respond to what you like. It's too risky to be a me-too.Find out from the customers to identify the REAL problems.Create a single&nbsp;superpower to tackle one of&nbsp;most identified problem.Once the company i [...] ]]></description><content:encoded><![CDATA[<div><div class="wsite-image wsite-image-border-none " style="padding-top:10px;padding-bottom:10px;margin-left:0;margin-right:0;text-align:center"> <a> <img src="http://www.hsufengko.com/uploads/8/0/5/7/8057674/stand-out-in-competition-1_orig.png" alt="Picture" style="width:auto;max-width:100%" /> </a> <div style="display:block;font-size:90%"></div> </div></div>  <div class="paragraph">You want to stand out when the competition is already there when entering a market. Think about three things:<br /><br /><ol><li>Form your own personality for your identity: Clone a service offer by a guru won't make you a guru. You want to have the content come out your personality, yourself. Clients respond to what you like. It's too risky to be a me-too.</li><li>Find out from the customers to identify the REAL problems.</li><li>Create a single&nbsp;superpower to tackle one of&nbsp;most identified problem.</li></ol><br />Once the company is positioned, then, move on to <a href="http://www.hsufengko.com/home/irresistible-product-offers">design irresistible products</a>.&nbsp;</div>  <div>  <!--BLOG_SUMMARY_END--></div>  <h2 class="wsite-content-title">references</h2>  <div class="paragraph"><ul><li><a href="https://www.acast.com/threemonthvacation/-113-part-1-how-to-stand-out-when-the-competition-is-already-outstanding">How To Stand Out When The Competition Is Already Outstanding</a></li></ul></div>]]></content:encoded></item><item><title><![CDATA[Flyweight Design Pattern Principle]]></title><link><![CDATA[http://www.hsufengko.com/notes/flyweight-design-pattern-principle]]></link><comments><![CDATA[http://www.hsufengko.com/notes/flyweight-design-pattern-principle#comments]]></comments><pubDate>Wed, 15 Jun 2016 23:44:16 GMT</pubDate><category><![CDATA[Design Pattern]]></category><guid isPermaLink="false">http://www.hsufengko.com/notes/flyweight-design-pattern-principle</guid><description><![CDATA[Flyweight pattern is a structural pattern in&nbsp;GoF&nbsp;as it&nbsp;supports large numbers of fine-grained objects efficiently. Since each fine-grained object (e.g. a character in an editor application) may incur overhead that adds up. This pattern shares objects in a pool (Flyweight Factory) to minimize memory use.      source: GoF       overview  Flyweight: A flyweight is a shared independent object with its own intrinsic state (e.g. character code) that is stateless or immutable. If the int [...] ]]></description><content:encoded><![CDATA[<div class="paragraph" style="text-align:left;">Flyweight pattern is a structural pattern in&nbsp;<a href="http://amzn.to/GJRuQC">GoF</a>&nbsp;as it&nbsp;<span>supports large numbers of fine-grained objects efficiently. Since each fine-grained object (e.g. a character in an editor application) may incur overhead that adds up. This pattern shares objects in a pool (Flyweight Factory) to minimize memory use.</span></div>  <div><div class="wsite-image wsite-image-border-none " style="padding-top:10px;padding-bottom:10px;margin-left:0px;margin-right:0px;text-align:center"> <a> <img src="http://www.hsufengko.com/uploads/8/0/5/7/8057674/255806_orig.jpg" alt="Picture" style="width:auto;max-width:100%" /> </a> <div style="display:block;font-size:90%">source: <a href="http://amzn.to/GJRuQC">GoF</a></div> </div></div>  <div>  <!--BLOG_SUMMARY_END--></div>  <h2 class="wsite-content-title" style="text-align:left;">overview</h2>  <div class="paragraph" style="text-align:left;"><strong>Flyweight</strong>: A flyweight is a shared independent object with its own intrinsic state (e.g. character code) that is stateless or immutable. If the intrinsic state is not going to be modified, then the object can be shared.&nbsp;Flyweight objects are shared among different contexts that hold extrinsic states (e.g.&nbsp;coordinate position in the document and its typographic style). These extrinsic state (out side of object) of the context will be passed by client object to the flyweight to operate. A flyweight makes as much of its state information extrinsic as possible and that is where the memory saving comes from.<br /><br /><strong>FlyweightFactory</strong>: Once you have flyweight, then you can have a FlyweightFactory as a Flyweight Pool which is a collection of Flyweights that are cached to be shared.&nbsp;&nbsp;FlyweightFactory is usually a Singleton&nbsp;to keep track of whether a particular flyweight has been generated and returns&nbsp;either a new instance or reference to one that it has already generated.<br /><br /></div>  <div class="paragraph" style="text-align:left;">Real world Flyweight use cases:&nbsp;<ol><li>Apply Flylweight to cells on a big board. For example, each cell on a 1000 by 1000 game of life game board can be a flyweight object to reduce memory footprint for each cell since extrinsic state are kelp outside of the Flyweight object.</li><li>The Java language specification requires&nbsp;that&nbsp;<a href="https://dzone.com/articles/design-patterns-in-the-real-world-flyweight?edition=155254&amp;utm_source=Weekly%20Digest&amp;utm_medium=email&amp;utm_campaign=wd%202016-06-08">integers between -128 and 127 be</a><a href="https://dzone.com/articles/design-patterns-in-the-real-world-flyweight?edition=155254&amp;utm_source=Weekly%20Digest&amp;utm_medium=email&amp;utm_campaign=wd%202016-06-08">&nbsp;'cached</a>' is actually a form of flyweight to conserve system resource.</li></ol></div>  <h2 class="wsite-content-title" style="text-align:left;">flyweight code example</h2>  <div id="829768325630237167"><div><style type="text/css">	#element-0a7c85c0-e829-4ef2-ad98-e64c04cd90f2 .code-editor--light {  padding: 20px 0px;}#element-0a7c85c0-e829-4ef2-ad98-e64c04cd90f2 .code-editor--light .header {  padding: 10px 20px;  font-weight: bold;  border-left: 1px solid #C9CDCF;  border-right: 1px solid #C9CDCF;  border-top: 1px solid #C9CDCF;  background-color: #F8F8F8;  color: #363B3E;}#element-0a7c85c0-e829-4ef2-ad98-e64c04cd90f2 .code-editor--light .header .paragraph {  margin: 0;}#element-0a7c85c0-e829-4ef2-ad98-e64c04cd90f2 .code-editor--light .body-code {  margin: 0;  border: 1px solid #C9CDCF;  background-color: #FFFFFF;  color: #666C70;}#element-0a7c85c0-e829-4ef2-ad98-e64c04cd90f2 .code-editor--dark {  padding: 20px 0px;}#element-0a7c85c0-e829-4ef2-ad98-e64c04cd90f2 .code-editor--dark .ace-tomorrow-night-eighties {  background-color: #363B3E;}#element-0a7c85c0-e829-4ef2-ad98-e64c04cd90f2 .code-editor--dark .header {  padding: 10px 20px;  font-weight: bold;  border-left: 1px solid #E0E1E2;  border-right: 1px solid #E0E1E2;  border-top: 1px solid #E0E1E2;  background-color: #666C70;  color: #FFFFFF;}#element-0a7c85c0-e829-4ef2-ad98-e64c04cd90f2 .code-editor--dark .header .paragraph {  margin: 0;}#element-0a7c85c0-e829-4ef2-ad98-e64c04cd90f2 .code-editor--dark .body-code {  margin: 0;  border: 1px solid #E0E1E2;  background-color: #363B3E;  color: #F8F8F8;}</style><div id="element-0a7c85c0-e829-4ef2-ad98-e64c04cd90f2" data-platform-element-id="270170748587580171-1.3.3" class="platform-element-contents">	<div class="code-editor--light">    <div class="header">        <div class="paragraph"><span style="color:rgb(136, 136, 136); font-weight:normal">FlyweightFactory class:</span></div>    </div>    <div class="body-code">        <pre class="editor"></pre>    </div></div></div><div style="clear:both;"></div></div></div>  <div id="719894928448245630"><div><style type="text/css">	#element-b09351b9-3118-4ae3-a5d5-04e10e065236 .code-editor--light {  padding: 20px 0px;}#element-b09351b9-3118-4ae3-a5d5-04e10e065236 .code-editor--light .header {  padding: 10px 20px;  font-weight: bold;  border-left: 1px solid #C9CDCF;  border-right: 1px solid #C9CDCF;  border-top: 1px solid #C9CDCF;  background-color: #F8F8F8;  color: #363B3E;}#element-b09351b9-3118-4ae3-a5d5-04e10e065236 .code-editor--light .header .paragraph {  margin: 0;}#element-b09351b9-3118-4ae3-a5d5-04e10e065236 .code-editor--light .body-code {  margin: 0;  border: 1px solid #C9CDCF;  background-color: #FFFFFF;  color: #666C70;}#element-b09351b9-3118-4ae3-a5d5-04e10e065236 .code-editor--dark {  padding: 20px 0px;}#element-b09351b9-3118-4ae3-a5d5-04e10e065236 .code-editor--dark .ace-tomorrow-night-eighties {  background-color: #363B3E;}#element-b09351b9-3118-4ae3-a5d5-04e10e065236 .code-editor--dark .header {  padding: 10px 20px;  font-weight: bold;  border-left: 1px solid #E0E1E2;  border-right: 1px solid #E0E1E2;  border-top: 1px solid #E0E1E2;  background-color: #666C70;  color: #FFFFFF;}#element-b09351b9-3118-4ae3-a5d5-04e10e065236 .code-editor--dark .header .paragraph {  margin: 0;}#element-b09351b9-3118-4ae3-a5d5-04e10e065236 .code-editor--dark .body-code {  margin: 0;  border: 1px solid #E0E1E2;  background-color: #363B3E;  color: #F8F8F8;}</style><div id="element-b09351b9-3118-4ae3-a5d5-04e10e065236" data-platform-element-id="270170748587580171-1.3.3" class="platform-element-contents">	<div class="code-editor--light">    <div class="header">        <div class="paragraph"><span style="color:rgb(136, 136, 136); font-weight:normal">Flyweight class:</span></div>    </div>    <div class="body-code">        <pre class="editor"></pre>    </div></div></div><div style="clear:both;"></div></div></div>  <div class="paragraph" style="text-align:left;">source:&nbsp;&#8203;<a href="http://techbus.safaribooksonline.com/book/programming/java/0201485397">Java&trade; Design Patterns: A Tutorial</a></div>  <h2 class="wsite-content-title" style="text-align:left;">when to use</h2>  <div class="paragraph" style="text-align:left;"><ol><li><span>Need use&nbsp;large numbers of objects when a simple repeated shared representation would save a large&nbsp;amount of memory.&#8203;<span>&#8203;&#8203;</span></span></li><li><span><span></span></span>Not often used at the application level in Java, more of a system resource&nbsp;management technique that is used at a lower level than Java.<br /></li></ol></div>  <h2 class="wsite-content-title" style="text-align:left;">comparison</h2>  <div class="paragraph" style="text-align:left;">Flyweight vs. Composite<ul><li>Flyweight tends to go with composite that contains Flyweight objects.</li></ul><br />Flyweight vs.&nbsp;<a href="http://www.hsufengko.com/home/strategy-design-pattern-example">Strategy</a><ul><li>Flyweights&nbsp;are small <a href="http://www.hsufengko.com/home/strategy-design-pattern-example">strategy classes</a> handled by the&nbsp;flyweight&nbsp;factory.</li><li>Both Strategy and Flyweight externalize extrinsic state.</li></ul></div>  <h2 class="wsite-content-title" style="text-align:left;">references</h2>  <div class="paragraph" style="text-align:left;"><ul><li><a href="http://www.holub.com/software/life/index.html">The Game of Life</a></li></ul></div>]]></content:encoded></item></channel></rss>