<?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/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Lotushints &#187; maintenance</title>
	<atom:link href="http://www.lotushints.com/tag/maintenance/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lotushints.com</link>
	<description>Lotus Notes tips &#38; tricks you always hoped you will not need</description>
	<lastBuildDate>Thu, 29 Dec 2011 09:47:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Design patterns &#8211; Part 10: Builder pattern</title>
		<link>http://www.lotushints.com/2009/05/design-patterns-part-10-builder-pattern/</link>
		<comments>http://www.lotushints.com/2009/05/design-patterns-part-10-builder-pattern/#comments</comments>
		<pubDate>Mon, 18 May 2009 06:00:47 +0000</pubDate>
		<dc:creator>Vladimir Kocjancic</dc:creator>
				<category><![CDATA[Basic]]></category>
		<category><![CDATA[Best practices]]></category>
		<category><![CDATA[Code optimization]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[Lotus Domino]]></category>
		<category><![CDATA[Object-oriented development]]></category>
		<category><![CDATA[absract factory]]></category>
		<category><![CDATA[builder]]></category>
		<category><![CDATA[custom classes]]></category>
		<category><![CDATA[LotusScript]]></category>
		<category><![CDATA[maintenance]]></category>
		<category><![CDATA[object-oriented]]></category>

		<guid isPermaLink="false">http://www.lotushints.com/?p=349</guid>
		<description><![CDATA[In part 10 of Design pattern series we will take look at Builder design pattern. Albeit much similarity, this pattern it is not to be mistaken with Abstract factory pattern. As Abstract Factory emphasizes a family of products and returns the product immediately, Builder focuses on constructing complex object step by step, returning product in [...]]]></description>
			<content:encoded><![CDATA[<p>In part 10 of <a href="/category/design-patterns/">Design pattern series</a> we will take look at Builder design pattern. Albeit much similarity, this pattern it is not to be mistaken with Abstract factory pattern. As Abstract Factory emphasizes a family of products and returns the product immediately, Builder focuses on constructing complex object step by step, returning product in final step.</p>
<blockquote><p>The intention of the <strong>The Builder pattern</strong> is to abstract steps of construction of objects so that different implementations of these steps can construct different representations of objects.</p></blockquote>
<p><span id="more-349"></span></p>
<p><strong>Huh?</strong></p>
<p>The best way to explain how builder pattern works is to look at the example. Imagine you have to build product presentation for a company that sells built PCs. For clarity&#8217;s sake, let&#8217;s pretend that they sell only two types of computers. One for basic office needs, running Linux OS and one for pro gaming needs running Windows.</p>
<p><strong>Let&#8217;s go!</strong></p>
<p>First, you need a product class. This class will be able to store product type, add components and display itself when needed. This allows you to build product with as many components as needed.</p>
<pre>Class CBuilderProduct
	Private m_strProductName As String
	Private m_strLParts List As String

	Sub New (productName As String)
		m_strProductName = productName
	End Sub

	Sub Add (part As String, desc As String)
		m_strLParts (part) = desc
	End Sub

	Sub Show ()
		Dim strDisplay As String

		strDisplay = "Product: " &amp; m_strProductName
		Forall part In m_strLParts
			strDisplay = strDisplay &amp; Chr(13) &amp;_
                      Listtag (part) &amp; ": " &amp; part
		End Forall
		Messagebox strDisplay
	End Sub
End Class</pre>
<p>Next, you need a builder class. This is an abstract class, only specifying methods and variables used by end product classes that inherit from it.</p>
<pre>Class CBuilder
	Private m_Product As CBuilderProduct

	Property Get Product As CBuilderProduct
		Set Product = m_Product
	End Property

	Sub AddOS()
	End Sub

	Sub AddPC()
	End Sub
End Class</pre>
<p>Now, you are ready to create real product classes. In our case, this classes will represent Basic and Pro products.</p>
<pre>Class CBuilderProductBasic As CBuilder
   Sub New()
      Set m_Product = New CBuilderProduct ("Basic Package")
   End Sub

   Sub AddOS()
      Call m_Product.Add ("Operating system", "Fedora Core 10")
   End Sub

   Sub AddPC()
      Call m_Product.Add ("Computer", "Basic home computer")
   End Sub
End Class

Class CBuilderProductPro As CBuilder
   Sub New()
      Set m_Product = New CBuilderProduct ("Pro Package")
   End Sub

   Sub AddOS()
      Call m_Product.Add ("Operating system", "Windows 7")
   End Sub

   Sub AddPC()
      Call m_Product.Add ("Computer", "Pro gaming computer")
   End Sub
End Class</pre>
<p>You are almost done. But first, you need a catalogue (or shop) class. This class will actually contain algorithm for building desired products. Beware that<em> builder</em> parameter of <em>Create </em>method must be of type <em>Variant </em>(it should be <em>CBuilder</em>) or you will get an error while compiling your code that will use this design pattern!</p>
<pre>Class CBuilderCatalog
	Sub Create (builder As Variant)
		Call builder.AddPC()
		Call builder.AddOS()
	End Sub
End Class</pre>
<p>To test the code, I wrote a simple agent that simply outputs two message boxes. One for each product.</p>
<pre>Sub Initialize
	Dim builder As CBuilder
	Dim shop As CBuilderCatalog

	Set shop = New CBuilderCatalog ()

	Set builder = New CBuilderProductBasic ()
	Call shop.Create (builder)
	Call builder.Product.Show()

	Set builder = New CBuilderProductPro ()
	Call shop.Create (builder)
	Call builder.Product.Show()
End Sub</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lotushints.com/2009/05/design-patterns-part-10-builder-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Design patterns &#8211; Part 9: Mediator pattern</title>
		<link>http://www.lotushints.com/2009/04/design-patterns-part-9-mediator-pattern/</link>
		<comments>http://www.lotushints.com/2009/04/design-patterns-part-9-mediator-pattern/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 08:00:28 +0000</pubDate>
		<dc:creator>Vladimir Kocjancic</dc:creator>
				<category><![CDATA[Best practices]]></category>
		<category><![CDATA[Code optimization]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[Lotus Domino]]></category>
		<category><![CDATA[Object-oriented development]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[custom classes]]></category>
		<category><![CDATA[LotusScript]]></category>
		<category><![CDATA[maintenance]]></category>
		<category><![CDATA[mediator]]></category>
		<category><![CDATA[object-oriented]]></category>

		<guid isPermaLink="false">http://www.lotushints.com/?p=320</guid>
		<description><![CDATA[This week, I present to you not much used, but quite useful Mediator pattern. Mediator pattern provides a unified interface to set of interfaces in a subsystem. Or, to simplify&#8230; Mediator pattern is mediator for communication between several classes. Example Now, the easiest way to explain this pattern is via example. Example itself is borrowed [...]]]></description>
			<content:encoded><![CDATA[<p>This week, I present to you not much used, but quite useful Mediator pattern.</p>
<blockquote><p><strong>Mediator pattern</strong> provides a unified interface to set of interfaces in a subsystem.</p></blockquote>
<p>Or, to simplify&#8230; Mediator pattern is mediator for communication between several classes.</p>
<p><span id="more-320"></span></p>
<p><strong>Example</strong></p>
<p>Now, the easiest way to explain this pattern is via example. Example itself is borrowed from <a href="http://www.dofactory.com/Patterns/PatternMediator.aspx" target="_blank">dofactory page</a>, but modified to fit LotusScript. It is about a simple support chat room. This chat room has several users of two types: admins and customers. I will call them participants. These participants can communicate amongst each other, presuming, they know user ids.</p>
<p>First, we need a chatroom template class, as we might end up with more than one chat room. Chat room will need to register participants and to be able to deliver messages to them.</p>
<pre>Class CChatroomTemplate
   Sub Register (participant As CParticipant)
   End Sub

   Sub Send (strFrom As String, strTo As String, strMsg As String)
   End Sub
End Class</pre>
<p>As participants need instance of chatroom class and chatroom needs list of participant class instances, we need to create chatroom and participant class frameworks and only then put code into it. Participants need to be able to send and receive messages. Finished classes are displayed below.</p>
<pre>Class CSupportChat As CChatroomTemplate
   m_LMembers List As CParticipant

   Sub Register(participant As CParticipant)
      If (Not Iselement (m_LMembers (participant.UserId))) Then
         Set m_LMembers (participant.UserId) = participant
      End If
      Set participant.Chatroom = Me
   End Sub

   Sub Send (strFrom As String, strTo As String, strMsg As String)
      Dim participant As CParticipant

      If (Not Iselement (m_LMembers (strTo))) Then Exit Sub
      Set participant = m_LMembers (strTo)
      Call participant.Receive (strFrom, strMsg)
   End Sub
End Class

Class CParticipant
   m_chatroom As CSupportChat
   m_strUserId As String

   Property Set Chatroom As CSupportChat
      Set m_chatroom = Chatroom
   End Property

   Property Get UserId As String
      UserId = m_strUserId
   End Property

   Property Set UserId As String
      m_strUserId = UserId
   End Property

   Sub new (strUserId As String)
      m_strUserId = strUserId
   End Sub

   Sub Send (strTo As String, strMsg As String)
      Call m_chatroom.Send (m_strUserId, strTo, strMsg)
   End Sub

   Sub Receive (strFrom As String, strMsg As String)
      Messagebox strFrom &amp; " to " &amp; m_strUserId &amp; ": " &amp; strMsg
   End Sub
End Class</pre>
<p>Now that base classes are set, it is time to create real participant classes. In our case, we need one for admins and one for regular users.</p>
<pre>Class CAdmin As CParticipant
   Sub new (strUserId As String)
   End Sub

   Sub Receive (strFrom As String, strMsg As String)
      Messagebox "Admin message"
      Call CParticipant..Receive (strFrom, strMsg)
   End Sub
End Class

Class CUser As CParticipant
   Sub new (strUserId As String)
   End Sub

   Sub Receive (strFrom As String, strMsg As String)
      Messagebox "User message"
      Call CParticipant..Receive (strFrom, strMsg)
   End Sub
End Class</pre>
<p><strong>Testing the code</strong></p>
<p>For testing purposes, I put it all in agent, created four users (of which one is admin) and sent 3 messages to admin and admin responded to first one. The code is below.</p>
<pre>Sub Initialize
   Dim chatroom As CSupportChat
   Dim user1 As CParticipant
   Dim user2 As CParticipant
   Dim user3 As CParticipant
   Dim user4 As CParticipant

   Set chatroom = New CSupportChat()
   Set user1 = New CUser ("User 1")
   Set user2 = New CUser ("User 2")
   Set user3 = New CUser ("User 3")
   Set user4 = New CAdmin ("Admin 1")

   Call chatroom.Register (user1)
   Call chatroom.Register (user2)
   Call chatroom.Register (user3)
   Call chatroom.Register (user4)

   Call user1.Send ("Admin 1", "Help?")
   Call user4.Send ("User 1", "What's wrong?")
   Call user2.Send ("Admin 1", "My server just crashed!!!")
   Call user3.Send ("Admin 1", "Network died!")
End Sub</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lotushints.com/2009/04/design-patterns-part-9-mediator-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Design patterns &#8211; Part 8: State pattern</title>
		<link>http://www.lotushints.com/2009/03/design-patterns-part-8-state-pattern/</link>
		<comments>http://www.lotushints.com/2009/03/design-patterns-part-8-state-pattern/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 08:00:35 +0000</pubDate>
		<dc:creator>Vladimir Kocjancic</dc:creator>
				<category><![CDATA[Best practices]]></category>
		<category><![CDATA[Code optimization]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[Lotus Domino]]></category>
		<category><![CDATA[Object-oriented development]]></category>
		<category><![CDATA[custom classes]]></category>
		<category><![CDATA[LotusScript]]></category>
		<category><![CDATA[maintenance]]></category>
		<category><![CDATA[object-oriented]]></category>
		<category><![CDATA[state]]></category>

		<guid isPermaLink="false">http://www.lotushints.com/?p=234</guid>
		<description><![CDATA[State pattern is probably most used in review cycles. The definition says: State pattern allows an object to appear as it can change its class by altering its behaviour and state. What are you talking about? Well, imagine you are in need to build a bug tracking database.  Bug reports in basics have four states. [...]]]></description>
			<content:encoded><![CDATA[<p>State pattern is probably most used in review cycles. The definition says:</p>
<blockquote><p><strong>State pattern</strong> allows an object to appear as it can change its class by altering its behaviour and state.</p></blockquote>
<p><strong>What are you talking about?</strong></p>
<p>Well, imagine you are in need to build a bug tracking database.  Bug reports in basics have four states. First they are <strong>unassigned</strong> until someone is solving them. When they are taken over, they become <strong>assigned</strong>, specifying that someone is already working on them. After bug fix has been produced, it is a good practice to <strong>send </strong>it<strong> to testing</strong>. Then it is up to QA to confirm that bug fix is <strong>complete </strong>or whether it is not.</p>
<p><span id="more-234"></span></p>
<p><strong>Show me the code!</strong></p>
<p>Example will be based on simple bug report specified above. However, I will skip actual action implementation as it varies based on application needs. Instead, I will use message box to print out the action report.</p>
<p>So, now, first what you need is a state abstract class that will implement all methods needed for transition between states (in our case: unassigned, assigned, send to testing and complete).</p>
<pre>Class CState
	Sub TakeOver()
	End Sub

	Sub SendToTesting()
	End Sub

	Sub Complete()
	End Sub
End Class</pre>
<p>Then, what you need is a context class that will be used when changing state of a bug report.</p>
<pre>Class CStateBugReport
   stateUnassigned As CState
   stateAssigned As CState
   stateReadyForTesting As CState
   stateCompleted As CState
   stateCurrent As CState

   Sub New
      Set stateUnassigned = New CStateUnassigned (Me)
      Set stateAssigned = New CStateAssigned (Me)
      Set stateReadyForTesting = New CStateSentToTesting (Me)
      Set stateCompleted = New CStateCompleted (Me)

      Set stateCurrent = stateUnassignedb
   End Sub

   Sub Assign()
      Call stateCurrent.TakeOver()
   End Sub

   Sub SendToTesting()
      Call stateCurrent.SendToTesting()
   End Sub

   Sub Complete()
      Call stateCurrent.Complete()
   End Sub

   Function GetAssignedState() As CState
      Set GetAssignedState = stateAssigned
   End Function

   Function GetReadyForTestingState() As CState
      Set GetReadyForTestingState = stateReadyForTesting
   End Function

   Function GetCompletedState() As CState
      Set GetCompletedState = stateCompleted
   End Function

   Sub SetState( state As CState )
      Set Me.stateCurrent = state
   End Sub
End Class</pre>
<p>And now, we need to implement all four states classes.</p>
<pre>Class CStateUnassigned As CState
   bugReport As CStateBugReport

   Sub New (bugReport As CStateBugReport)
      Set Me.bugReport = bugReport
   End Sub

   Sub TakeOver ()
      Messagebox "Took over!"
      Call Me.bugReport.SetState (Me.bugReport.GetAssignedState())
   End Sub

   Sub SendToTesting()
      Messagebox "Unassigned reports cannot be sent to testing"
   End Sub

   Sub Complete()
      Messagebox "Unassigned reports cannot be completed"
   End Sub
End Class

Class CStateAssigned As CState
   bugReport As CStateBugReport

   Sub New (bugReport As CStateBugReport)
      Set Me.bugReport = bugReport
   End Sub

   Sub TakeOver ()
      Messagebox "Report already assigned"
   End Sub

   Sub SendToTesting()
      Messagebox "Sent to testing!"
      Call Me.bugReport.SetState
         (Me.bugReport.GetReadyForTestingState())
   End Sub

   Sub Complete()
      Messagebox "Untested reports cannot be completed"
   End Sub
End Class

Class CStateSentToTesting As CState
   bugReport As CStateBugReport

   Sub New (bugReport As CStateBugReport)
      Set Me.bugReport = bugReport
   End Sub

   Sub TakeOver ()
      Messagebox "Report already assigned"
   End Sub

   Sub SendToTesting()
      Messagebox "Report already in testing"
   End Sub

   Sub Complete()
      Messagebox "Complete!"
      Call Me.bugReport.SetState (Me.bugReport.GetCompletedState())
   End Sub
End Class

Class CStateCompleted As CState
   bugReport As CStateBugReport

   Sub New (bugReport As CStateBugReport)
      Set Me.bugReport = bugReport
   End Sub

   Sub TakeOver ()
      Messagebox "Report already completed"
   End Sub

   Sub SendToTesting()
      Messagebox "Report already completed"
   End Sub

   Sub Complete()
      Messagebox "Report already completed"
   End Sub
End Class</pre>
<p>This is all there is to it. To test it, I wrote a simple agent that goes through states and in each new state also tests wrong transitions (e.g. from unassigned to complete etc.).</p>
<pre>Sub Initialize
	Dim bugReport As New CStateBugReport()

	Call bugReport.SendToTesting()
	Call bugReport.Complete()

	Call bugReport.Assign()
	Call bugReport.Assign()
	Call bugReport.Complete()

	Call bugReport.SendToTesting()
	Call bugReport.Assign()
	Call bugReport.SendToTesting()

	Call bugReport.Complete()
	Call bugReport.Assign()
	Call bugReport.SendToTesting()
	Call bugReport.Complete()
End Sub</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lotushints.com/2009/03/design-patterns-part-8-state-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calling Java classes from LotusScript</title>
		<link>http://www.lotushints.com/2009/02/calling-java-classes-from-lotusscript/</link>
		<comments>http://www.lotushints.com/2009/02/calling-java-classes-from-lotusscript/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 08:00:19 +0000</pubDate>
		<dc:creator>Vladimir Kocjancic</dc:creator>
				<category><![CDATA[Best practices]]></category>
		<category><![CDATA[Code optimization]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[Lotus Notes]]></category>
		<category><![CDATA[Object-oriented development]]></category>
		<category><![CDATA[adapter]]></category>
		<category><![CDATA[custom classes]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[LotusScript]]></category>
		<category><![CDATA[maintenance]]></category>
		<category><![CDATA[object-oriented]]></category>
		<category><![CDATA[user registration]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.lotushints.com/?p=210</guid>
		<description><![CDATA[Have you ever wondered how you could call already written and quite useful Java classes in your LotusScript code? To me, this moment was, when I was trying to implement other department&#8217;s code into my own. Unfortunately I wasn&#8217;t skilled enough in ways of object development, LS2J  and googling back then to actually figure out [...]]]></description>
			<content:encoded><![CDATA[<p><span>Have you ever wondered how you could call already written and quite useful Java classes in your <span>LotusScript</span> code? To me, this moment was, when I was trying to implement other department&#8217;s code into my own. Unfortunately I wasn&#8217;t skilled enough in ways of object development, LS2J  and googling back then to actually figure out that was possible. I remember thinking: &#8220;IBM implemented Java in Lotus Notes, they must have done some adaptor for it.&#8221;, but was unable to figure it out. Until couple of years back, when I got a </span><a href="http://www.randsinrepose.com/archives/2002/07/10/the_dark_underbelly_of_holy_shit.html">Holy shit!</a> moment, finding <a href="http://www.nsftools.com/blog/blog-11-2004#11-19-04">this blog post</a>.</p>
<p><span id="more-210"></span><strong>But why would I need that?</strong></p>
<p><span>As you can see from the above examples, you can implement Java functionality to your <span>LotusScript</span> code. This can be good if your Java programming skills aren&#8217;t that great or you already have some code in <span>LotusScript</span> and you wish to add functionality. For me, it would do fine in cases where I converted documents in a database to PDF on user request, or when I needed an agent to <span>login</span> user to notes via web in the background, or as I mentioned, when I needed to implement some functionality from other department in my already existing code. Instead, I re-wrote several agents into Java, which in the end didn&#8217;t prove to be that bad of a decision, but about that some other day.</span></p>
<p><strong>But how do I do that?</strong></p>
<p>There is a functionality called <strong>LS2J </strong><span>that does exactly that for you. If you will, you can imagine it as an adaptor for <span>LotusScript</span> that allows you to call Java classes. I will give you a small example. It is based on my user <span>login</span> class, although, there is really no code there to log in the user.</span></p>
<p><span>First you need to create/obtain a java library that does what you want. I named that library <span>jclass</span>:<span>UserLogin</span>.</span></p>
<pre><span>public class CUserLogin {
   String m_strUsername;
   String m_strPassword;

   public void Initialize(String strUsername, String strPassword) {
      if ((strUsername.length() == 0) ||
          (strPassword.length() == 0))
         return;

      m_strUsername = strUsername;
      m_strPassword = strPassword;
   }

   public boolean run() {
      // add code that will perform auto-login
      return true;
   }
}</span></pre>
<p><span>Then, I strongly suggest you create a <span>LotusScript</span> library, containing a class that will do actual Java to <span>LotusScript</span> conversion. Why? So you have to do it only once.</span><br />
My script library called class:UserLogin is depicted below.</p>
<pre><span><span>Uselsx</span> "*<span>javacon</span>"</span>
<span>Use "<span>jclass</span>:<span>UserLogin</span>"</span>

<span>Class <span>CUserLogin</span></span>
<span>	<span>loginObj</span> As <span>JavaObject</span></span>

<span>	Sub New (<span>strUsername</span> As String, <span>strPassword</span> As String)</span>
		Dim js As New JAVASESSION
<span>		Dim <span>loginClass</span> As JAVACLASS</span>

<span>		Set <span>loginClass</span> = <span>js</span>.<span>GetClass</span> ("<span>CUserLogin</span>")</span>
<span>		Set <span>loginObj</span> = <span>loginClass</span>.<span>CreateObject</span> ()</span>

<span>		Call <span>loginObj</span>.Initialize (<span>strUsername</span>, <span>strPassword</span>)</span>
	End Sub

	Function run() As Boolean
<span>		run = <span>loginObj</span>.run()</span>
	End Function
End Class</pre>
<p><span>And that is it. Now all you have to do, is use this script library in your code. Where you need it. I created a simple agent that will pop-up a window with text depicting <span>login</span> success.</span></p>
<pre><span>Use "class:<span>UserLogin</span>"</span>

Sub Initialize
<span>	Dim <span>userLogin</span> As <span>CUserLogin</span></span>

<span>	Set <span>userLogin</span> = New <span>CUserLogin</span> ("test", "test123")</span>
	If (userLogin.run()) Then
<span>		<span>Messagebox</span> "<span>Login</span> succeeded"</span>
	Else
<span>		<span>Messagebox</span> "<span>Login</span> failed!"</span>
	End If
End Sub</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lotushints.com/2009/02/calling-java-classes-from-lotusscript/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Design patterns &#8211; Part 7: Template method pattern</title>
		<link>http://www.lotushints.com/2009/02/design-patterns-part-7-template-method-pattern/</link>
		<comments>http://www.lotushints.com/2009/02/design-patterns-part-7-template-method-pattern/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 08:00:35 +0000</pubDate>
		<dc:creator>Vladimir Kocjancic</dc:creator>
				<category><![CDATA[Best practices]]></category>
		<category><![CDATA[Code optimization]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[Lotus Domino]]></category>
		<category><![CDATA[Object-oriented development]]></category>
		<category><![CDATA[custom classes]]></category>
		<category><![CDATA[LotusScript]]></category>
		<category><![CDATA[maintenance]]></category>
		<category><![CDATA[object-oriented]]></category>
		<category><![CDATA[template method]]></category>

		<guid isPermaLink="false">http://www.lotushints.com/?p=200</guid>
		<description><![CDATA[In this article, I would like to present you a design pattern that is not so common, but for sure, I wish, that in the past I would have used it. It would certainly make my life much easier. So, what is this Template method pattern all about? The Template Method Pattern defines the skeleton [...]]]></description>
			<content:encoded><![CDATA[<p>In this article, I would like to present you a design pattern that is not so common, but for sure, I wish, that in the past I would have used it. It would certainly make my life much easier. So, what is this Template method pattern all about?</p>
<blockquote><p><strong>The Template Method Pattern</strong> defines the skeleton of a an algorithm in one method. Some steps are deferred to subclasses, which are allowed to alter certain algorithm steps without changing the skeleton of an algorithm.</p></blockquote>
<p><span id="more-200"></span></p>
<p><strong>Say what?</strong></p>
<p>Well, to simplify the definition, let&#8217;s look at an example. Imagine you have several product types. Your assigned task was to build a product catalogue on the web. All product types will use tables for representation, however not all products can be displayed the same. This is a perfect task for Template method pattern.</p>
<p><strong>But why?</strong></p>
<p>Think about it. Your catalogue needs to be displayed differently for each product, meaning you need to get different sets of product for each display. I agree, you could have written multiple agents, or just use multiple methods in an agent, but think about maintainability. And on top of it all, to display each product type, your algorithm is the same. First you need to do some <strong>initialization</strong>, then you need to <strong>select</strong> desired products. Next step is to <strong>process</strong> document set to create a display. In the end, all you need to do is <strong>print</strong> the results and <strong>terminate</strong> (or perform a clean up). Steps <strong>select</strong> and <strong>process</strong> are product type dependant. All other steps of the algorithm are common.</p>
<p><strong>Example</strong></p>
<p>For example let&#8217;s pretend that we have two types of products: regular classroom courses and e-courses. Regular classroom courses (or just courses) are scheduled courses, while e-courses are actually a 1 month subscription to some content (like video, PDF, etc.).</p>
<p>First, we need to create some storage classes: CProduct and CPrice, that will store information about products. This is more efficient than just have a collection of NotesDocuments.</p>
<pre>Class CPrice
	Public strDesc As String
	Public dPrice As Double
End Class

Class CProduct
	m_strName As String
	m_strType As String
	Public m_Price() As CPrice

	Property Get Label As String
		Label = Me.m_strName
	End Property

	Property Get MyType As String
		MyType = Me.m_strType
	End Property

	Sub New (strName As String, strType As String)
		Me.m_strName = strName
		Me.m_strType = strType
		Redim Me.m_Price (0)
	End Sub

	Sub AddPrice (strDesc As String, dPrice As Double)
		Dim nIndex As Integer

		nIndex = 0
		If (Not Me.m_Price (0) Is Nothing) Then
                     nIndex = Ubound (Me.m_Price) + 1
              End If

		Redim Preserve Me.m_price (nIndex)
		Set Me.m_price (nIndex) = New CPrice
		Me.m_Price (nIndex).strDesc = strDesc
		Me.m_Price (nIndex).dPrice = dPrice
	End Sub
End Class</pre>
<p>Class CPrice contains a description of price (subscription or schedule date) and the price itself. Class CProduct defines a product. Each product can have multiple prices.</p>
<p>Now, to our abstract class that will define the algorithm and required methods.</p>
<pre>Class CTemplateProduct
	m_strHtml As String
	m_products() As CProduct

	Sub Initialize()
		Redim m_products (0)
	End Sub

	Sub Select()
	End Sub

	Sub Process()
	End Sub

	Sub Print()
		Print m_strHtml
	End Sub

	Sub Terminate()
		Erase m_products
	End Sub

	Sub Run()
		Call Me.Initialize()
		Call Me.Select()
		Call Me.Process()
		Call Me.Print()
		Call Me.Terminate()
	End Sub
End Class</pre>
<p>As you can see, methods Initialize, Print and Terminate are already implemented.<br />
Next, we need to create classes for each product type. These classes will inherit from the abstract class.</p>
<pre>Class CTemplateCourse As CTemplateProduct
   Sub Select()
      Redim Preserve Me.m_products (1)
      Set Me.m_products (0) =
         New CProduct ("Course 1", "Lecture")

      Call Me.m_products (0).AddPrice ("Feb 3rd, 2009", 1000.0)

      Set Me.m_products (1) =
         New CProduct ("Exam 1", "Lecture &amp; exam")

      Call Me.m_products (1).AddPrice ("Feb 20th, 2009", 2000.0)
   End Sub

   Sub Process()
      Dim n As Integer
      Dim nPrice As Integer
      Dim nLBound As Integer
      Dim nUBound As Integer
      Me.m_strHtml = {&lt;table border="0"&gt;}

      For n = Lbound (Me.m_products) To Ubound (Me.m_products)
         Me.m_strHtml = Me.m_strHtml &amp; {&lt;tbody&gt;&lt;tr&gt;}
         Me.m_strHtml = Me.m_strHtml &amp; {&lt;td colspan="2"&gt;}
         Me.m_strHtml = Me.m_strHtml &amp; _
         Me.m_products (n).Label &amp; { - }

         Me.m_strHtml = Me.m_strHtml &amp; _
         Me.m_products (n).MyType &amp; {&lt;/td&gt;}

         Me.m_strHtml = Me.m_strHtml &amp; {&lt;/tr&gt;}
         Me.m_strHtml = Me.m_strHtml &amp; {&lt;tr&gt;}

         nLBound = Lbound(Me.m_products (n).m_Price)
         nUBound = Ubound (Me.m_products (n).m_Price)
         For nPrice = nLBound To nUBound
            Me.m_strHtml = Me.m_strHtml &amp; {&lt;td&gt;}
            Me.m_strHtml = Me.m_strHtml &amp; _
            Me.m_products (n).m_Price (nPrice).strDesc 

            Me.m_strHtml = Me.m_strHtml &amp; {&lt;/td&gt;}
            Me.m_strHtml = Me.m_strHtml &amp; {&lt;td&gt;}
            Me.m_strHtml = Me.m_strHtml &amp; _
            Me.m_products (n).m_Price (nPrice).dPrice
            Me.m_strHtml = Me.m_strHtml &amp; {&lt;/td&gt;}
         Next
         Me.m_strHtml = Me.m_strHtml &amp; {&lt;/tr&gt;}
      Next

      Me.m_strHtml = Me.m_strHtml &amp; {&lt;/tbody&gt;}
   End Sub
End Class

Class CTemplateECourse As CTemplateProduct
   Sub Select()
      Redim Preserve Me.m_products (1)
      Set Me.m_products (0) =
         New CProduct ("E-Course 1", "eBook")
      Call Me.m_products (0).AddPrice ("1 month", 100.0)

      Set Me.m_products (1) =
         New CProduct ("E-Course 2", "ePresentation")

      Call Me.m_products (1).AddPrice ("1 month", 200.0)
   End Sub

   Sub Process()
      Dim n As Integer
      Dim nPrice As Integer
      Dim nLBound As Integer
      Dim nUBound As Integer

      Me.m_strHtml = {&lt;table border="0"&gt;}

      For n = Lbound (Me.m_products) To Ubound (Me.m_products)
         Me.m_strHtml = Me.m_strHtml &amp; {&lt;tbody&gt;&lt;tr&gt;}
         Me.m_strHtml = Me.m_strHtml &amp; {&lt;td&gt;} &amp;_
         Me.m_products (n).Label &amp; {&lt;/td&gt;}
         Me.m_strHtml = Me.m_strHtml &amp; {&lt;td&gt;} &amp; _
         Me.m_products (n).MyType &amp; {&lt;/td&gt;}

         nLBound = Lbound(Me.m_products (n).m_Price)
         nUBound = Ubound (Me.m_products (n).m_Price)
         For nPrice = nLBound To nUBound
            Me.m_strHtml = Me.m_strHtml &amp; {&lt;td&gt;} &amp; _
            Me.m_products (n).m_Price (nPrice).strDesc

            Me.m_strHtml = Me.m_strHtml &amp; {&lt;br/&gt;} &amp; _
            Me.m_products (n).m_Price (nPrice).dPrice &amp; {&lt;/td&gt;}
         Next
         Me.m_strHtml = Me.m_strHtml &amp; {&lt;/tr&gt;}
      Next

      Me.m_strHtml = Me.m_strHtml &amp; {&lt;/tbody&gt;&lt;/table&gt;}
   End Sub
End Class</pre>
<p>As you can no doubt see, I have simplified the Select method (this is due to me being to lazy to actually create a form, a view and some 6 documents). Also, method Process creates different HTML for each product type.</p>
<p>Interesting thing, this is about it.<br />
All you have to do is some code that will use this. Here is my test agent, that should be run via browser.</p>
<pre>Sub Initialize
	Dim course As CTemplateProduct
	Dim eCourse As CTemplateProduct

	Set course = New CTemplateCourse ()
	Call course.Run()

	Set eCourse = New CTemplateECourse()
	Call eCourse.Run()
End Sub</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lotushints.com/2009/02/design-patterns-part-7-template-method-pattern/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Problems with names.nsf refresh</title>
		<link>http://www.lotushints.com/2009/02/problems-with-namesnsf-refresh/</link>
		<comments>http://www.lotushints.com/2009/02/problems-with-namesnsf-refresh/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 08:00:49 +0000</pubDate>
		<dc:creator>Vladimir Kocjancic</dc:creator>
				<category><![CDATA[Lotus Domino]]></category>
		<category><![CDATA[database cache]]></category>
		<category><![CDATA[maintenance]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[user registration]]></category>

		<guid isPermaLink="false">http://www.lotushints.com/?p=174</guid>
		<description><![CDATA[At work, we experienced an interesting problem. We use public servers names.nsf to register new web users. However, a couple of months back, that suddenly stopped working. A person document was created, user was added to all required groups, but upon login, a user would obtain an error that he is not authorized to perform [...]]]></description>
			<content:encoded><![CDATA[<p>At work, we experienced an interesting problem. We use public servers names.nsf to register new web users. However, a couple of months back, that suddenly stopped working. A person document was created, user was added to all required groups, but upon login, a user would obtain an error that he is not authorized to perform that operation. The only thing that did the trick was to restart domino server.</p>
<p><span id="more-174"></span></p>
<p>We opened PMR and had a huge testing with IBM support team. However, it was not until LotusSphere, when one of our developers got a hint we never expected. In servers .ini file, there was a following line: <strong>NLCACHE_VERSION=4</strong>. Now, apparently setting NLCACHE_VERSION to value 4 causes some sort of a bug that stops cache from refreshing. However, if you delete parameter from .ini file, default value of 2 will be set for this parameter and everything will work just fine.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lotushints.com/2009/02/problems-with-namesnsf-refresh/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Version control and bug tracking</title>
		<link>http://www.lotushints.com/2009/01/version-control-and-bug-tracking/</link>
		<comments>http://www.lotushints.com/2009/01/version-control-and-bug-tracking/#comments</comments>
		<pubDate>Sat, 24 Jan 2009 12:51:10 +0000</pubDate>
		<dc:creator>Vladimir Kocjancic</dc:creator>
				<category><![CDATA[Basic]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bug tracking]]></category>
		<category><![CDATA[Lotus Notes]]></category>
		<category><![CDATA[maintenance]]></category>
		<category><![CDATA[organization]]></category>
		<category><![CDATA[version control]]></category>

		<guid isPermaLink="false">http://www.lotushints.com/?p=169</guid>
		<description><![CDATA[In my years of developing software, I come to realize that what every software development department needs is: some sort of IDE with a compiler version control and bug tracking. Usually you get stuck with IDE with a compiler. Everything else is up to you. But how are things in Lotus Notes? Version control As [...]]]></description>
			<content:encoded><![CDATA[<p>In my years of developing software, I come to realize that what every software development department needs is:</p>
<ul>
<li>some sort of IDE with a compiler</li>
<li>version control</li>
<li>and bug tracking.</li>
</ul>
<p>Usually you get stuck with IDE with a compiler. Everything else is up to you. But how are things in Lotus Notes?<br />
<span id="more-169"></span><br />
<strong>Version control</strong></p>
<p>As expected Lotus Designer doesn&#8217;t have an integrated version control software. Not yet anyway. They are planing to build subclipse to work in new 8.5 designer, but that still needs some time. Also most people are probably still stuck at R7.</p>
<p>Well, one of the things you could use is Teamstudio Ciao!. This is a payed software meaning that either it becomes your department policy to use it or you will never use it. I had a chance of working with Ciao and I have to say that I was less than impressed. But that is just me. I know a lot of people using it without any drawbacks and with lack of tools out there, this is probably the way to go.</p>
<p>Next widely used option is to use separate templates for each and every version of your application. There are two things wrong with this. One is that there is no way any developer would do a new template just for fixing one single agent. Second one is that I am yet to see a consistent template policy.</p>
<p>Another possibility is to copy your database locally and then import it into Subversion (SVN) or perhaps write a script that would periodically do that for you. The thing is that you won&#8217;t be able to just revert to desired version of the database without deleting the existing one. There is one other option. You could export objects (agents, views etc.) as DXL, import it into SVN and then when needed import DXL back to the database. However, DXL is not 100% representation of design elements. Thus I wouldn&#8217;t recommend it.</p>
<p>As mentioned there is a subclipse project that would enable subclipse in Domino Designer 8.5. Subclipse is Eclipse plug-in for Subversion. And since Domino Designer 8.5 is built on Eclipse framework, this would finally solve most of our version control issues.</p>
<p><strong>Bug Tracking</strong></p>
<p>Why bug tracking? Well, I am yet to see software without bugs. And the thing that helps the most is some sort of bug tracking engine. However, oddly enough, this is the part rarely seen and used. Typical bug tracking process should go like this:</p>
<ul>
<li>someone reports a bug</li>
<li>developer is assigned to the bug</li>
<li>developer fixes the bug</li>
<li>third person (inside a company and related to project the bug was reported for) tests the fixed code</li>
<li>bug report is completed.</li>
</ul>
<p>Now, show of hands. How many of you have this process implemented in your development cycle? I thought so. But being a Notes developer, what are your options?</p>
<p>There is a great open source project at openntf.org called <a href="http://www.openntf.org/Projects/pmt.nsf/ProjectLookup/BugTracker">BugTracker</a>. Another option is to use some commercial product like <a href="http://www.trackersuite.com/frame_help_desk_software.html">Trackersuit Help Desk Software</a> or similar.</p>
<p>If you are not attached to domino apps only, there are tons of open source applications for bug tracking. Probably most known amongst them are <a href="http://www.mantisbt.org/">Mantis BugTracker</a> and <a href="http://www.bugzilla.org/download/">Bugzilla</a>.</p>
<p>The most inappropriate systems for bug tracking I have seen thus far are internal forum and wiki. These applications are not meant to be bug trackers. So, please, don&#8217;t use them as such.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lotushints.com/2009/01/version-control-and-bug-tracking/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Multilingual applications</title>
		<link>http://www.lotushints.com/2008/10/multilingual-applications/</link>
		<comments>http://www.lotushints.com/2008/10/multilingual-applications/#comments</comments>
		<pubDate>Mon, 06 Oct 2008 08:00:01 +0000</pubDate>
		<dc:creator>Vladimir Kocjancic</dc:creator>
				<category><![CDATA[Basic]]></category>
		<category><![CDATA[Code optimization]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[Lotus Notes]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[maintenance]]></category>
		<category><![CDATA[Multilingual]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[string repository]]></category>

		<guid isPermaLink="false">http://www.lotushints.com/?p=35</guid>
		<description><![CDATA[The other day, at work, there was a discussion about possible ways to create an application that could easily be ported into different languages. At the end, we got stuck on two possibilities. One was to simply make a new copy of the database and translate all design elements. The second one was to have [...]]]></description>
			<content:encoded><![CDATA[<p>The other day, at work, there was a discussion about possible ways to create an application that could easily be ported into different languages. At the end, we got stuck on two possibilities. One was to simply make a new copy of the database and translate all design elements. The second one was to have a string repository (either in the same database or in central place) and then load strings from there.<span id="more-35"></span></p>
<p><strong>Which to pick? </strong></p>
<p>With first possibility, we can say goodbye to design templates and every database in different language has to be maintained separately which can have major influence on maintenance costs. Also re-translating every prompt could end up in code corruption. On the other hand, as all strings are in design elements, there are no ill effects on application performance. Second possibility allows each and every database design to be updated from the same template, thus minimizing code corruption risks and maintenance costs. However, loading all those strings into design elements can present a significant performance issue.</p>
<p><strong>Test preparations</strong></p>
<p>I decided to create a test database that would shed some light upon performance issues with using string repository. I managed to randomly create 300 string resources via agent. Then, I created 3 forms containing 200 computed values each. Computed values would first obtain a random number from 1 to 300 and then load specific string. Why 3 forms? Two of them were using a bad programming habit I came across, using NoCache and ReCache parameters in all @DbLookups. The last one was the one with first @DbLookup re-caching data and all others reading from that cache.</p>
<p>I created another 3 forms, similar to these, but with a little twist. Those forms would read strings from different database.</p>
<p>Now all that I lacked was a sufficient timing system. That was a piece of cake. I created a timer class, which basically reads tick count using GetThreadInfo function on QueryOpen and PostOpen events on the form. Then it recalculates tick count difference into seconds and prints a result in the status bar of Notes client.</p>
<p><strong>The test</strong></p>
<p>I decided to perform a test on a working development server. Each form was used to create 10 documents twice. Once on a regular database and once on full text indexed one. Results of testing (in seconds; comma delimits decimal places) are displayed in images below.</p>
<div id="attachment_39" class="wp-caption alignnone" style="width: 501px"><a href="http://www.lotushints.com/wp-content/uploads/2008/10/ma_graph1.gif"><img class="size-full wp-image-39" title="ma_graph1" src="http://www.lotushints.com/wp-content/uploads/2008/10/ma_graph1.gif" alt="Results when string repository is in same database" width="491" height="302" /></a><p class="wp-caption-text">Results when string repository is in the same database</p></div>
<div id="attachment_40" class="wp-caption alignnone" style="width: 502px"><a href="http://www.lotushints.com/wp-content/uploads/2008/10/ma_graph2.gif"><img class="size-full wp-image-40" title="ma_graph2" src="http://www.lotushints.com/wp-content/uploads/2008/10/ma_graph2.gif" alt="Results when string repository is in same full-text indexed database" width="492" height="302" /></a><p class="wp-caption-text">Results when string repository is in same full-text indexed database</p></div>
<div id="attachment_41" class="wp-caption alignnone" style="width: 503px"><a href="http://www.lotushints.com/wp-content/uploads/2008/10/ma_graph3.gif"><img class="size-full wp-image-41" title="ma_graph3" src="http://www.lotushints.com/wp-content/uploads/2008/10/ma_graph3.gif" alt="Results when string repository is in different database" width="493" height="304" /></a><p class="wp-caption-text">Results when string repository is in different database</p></div>
<div id="attachment_38" class="wp-caption alignnone" style="width: 504px"><a href="http://www.lotushints.com/wp-content/uploads/2008/10/ma_graph4.gif"><img class="size-full wp-image-38" title="ma_graph4" src="http://www.lotushints.com/wp-content/uploads/2008/10/ma_graph4.gif" alt="Results when string repository is in different full-text indexed database" width="494" height="305" /></a><p class="wp-caption-text">Results when string repository is in different full-text indexed database</p></div>
<p><strong>The conclusion</strong></p>
<p>Results were a surprise. With forms opening with delays from 0.9 seconds up, there is no way of using string resources to load each and every string used in an application. Even if string repository is in the very same database and the database is full text indexed.</p>
<p>Obviously separate databases are no big solution as well, due to above mentioned reasons. Perhaps one could get away with having separate forms/sub-forms and only use string repository for prompts and in scripts and thus avoid possibility to corrupt application code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lotushints.com/2008/10/multilingual-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

