<?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; Object-oriented development</title>
	<atom:link href="http://www.lotushints.com/category/object-oriented-development/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>Wed, 14 Jul 2010 06:00:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Lotus Notes 8.5.1</title>
		<link>http://www.lotushints.com/2009/10/lotus-notes-8-5-1/</link>
		<comments>http://www.lotushints.com/2009/10/lotus-notes-8-5-1/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 06:00:47 +0000</pubDate>
		<dc:creator>Vladimir Kocjancic</dc:creator>
				<category><![CDATA[Lotus Domino]]></category>
		<category><![CDATA[Lotus Notes]]></category>
		<category><![CDATA[Object-oriented development]]></category>
		<category><![CDATA[custom classes]]></category>
		<category><![CDATA[LotusScript]]></category>

		<guid isPermaLink="false">http://www.lotushints.com/?p=444</guid>
		<description><![CDATA[With the abundance of posts out there, I thought I would chip in my 5 cents worth. Yes, I know I am a bit late. Release 8.5.1 is for LotusScript developer everything he could ever hope for. Specially if you are into OO programming. Finally you don&#8217;t have to check your old classes what parameters [...]]]></description>
			<content:encoded><![CDATA[<p>With the abundance of posts out there, I thought I would chip in my 5 cents worth. Yes, I know I am a bit late.</p>
<p>Release 8.5.1 is for LotusScript developer everything he could ever hope for. Specially if you are into OO programming. Finally you don&#8217;t have to check your old classes what parameters they take, you can easily locate them by going to class definition and helper works. Now, you have really no excuse to start OO development in LotusScript.</p>
<p>On the other hand, 8.5.1 introduced some strange bugs. My colleague found an interesting bug while editing forms. For some reason, formula wasn&#8217;t saved when the document was. I think he solved it by removing formula completely and then re-pasting it back. Another funny thing is code formatting. Still not working properly. Hope to see it solved in 8.5.2.</p>
<p>Don&#8217;t get me wrong. I take 8.5.1 over any release any day.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lotushints.com/2009/10/lotus-notes-8-5-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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[Intermediate]]></category>
		<category><![CDATA[Lotus Domino]]></category>
		<category><![CDATA[Object-oriented development]]></category>
		<category><![CDATA[design patterns]]></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[Intermediate]]></category>
		<category><![CDATA[Lotus Domino]]></category>
		<category><![CDATA[Object-oriented development]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[design patterns]]></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[Intermediate]]></category>
		<category><![CDATA[Lotus Domino]]></category>
		<category><![CDATA[Object-oriented development]]></category>
		<category><![CDATA[design patterns]]></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>4</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[Intermediate]]></category>
		<category><![CDATA[Lotus Domino]]></category>
		<category><![CDATA[Object-oriented development]]></category>
		<category><![CDATA[design patterns]]></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>0</slash:comments>
		</item>
		<item>
		<title>Design patterns &#8211; Part 6: Observer pattern</title>
		<link>http://www.lotushints.com/2009/02/design-patterns-part-6-observer-pattern/</link>
		<comments>http://www.lotushints.com/2009/02/design-patterns-part-6-observer-pattern/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 08:00:33 +0000</pubDate>
		<dc:creator>Vladimir Kocjancic</dc:creator>
				<category><![CDATA[Basic]]></category>
		<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[design patterns]]></category>
		<category><![CDATA[custom classes]]></category>
		<category><![CDATA[LotusScript]]></category>
		<category><![CDATA[object-oriented]]></category>
		<category><![CDATA[observer]]></category>

		<guid isPermaLink="false">http://www.lotushints.com/?p=183</guid>
		<description><![CDATA[One of the most used patterns is also a pattern that hears by the name Observer. What does it do? Well, imagine you have a stock portfolio and you need to notify your investors every time the value of their stock changes. First, your investors need to subscribe to the stock they would like to [...]]]></description>
			<content:encoded><![CDATA[<p>One of the most used patterns is also a pattern that hears by the name Observer. What does it do? Well, imagine you have a stock portfolio and you need to notify your investors every time the value of their stock changes. First, your investors need to <strong>subscribe</strong> to the stock they would like to be notified about. Next, whenever new stock value is <strong>published</strong>, subscribers are notified. Much like RSS subscription. But what about definition:</p>
<blockquote><p><strong>The Observer pattern</strong> defines a one-to-many dependency between objects so that when one object changes state, all of its dependants are notified and updated automatically.</p></blockquote>
<p><span id="more-183"></span><br />
<strong>Fine, but what can I do with that?</strong></p>
<p>We will build an above mentioned example of a stock and it&#8217;s investors. First, you will need to create an observer abstract class:</p>
<pre>Class CObserver
	m_strName As String

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

	Sub New (strName As String)
		Me.m_strName = strNAme
	End Sub

	Sub Update()
	End Sub
End Class</pre>
<p>As you can see, it contains a name, which will be used as unique id, a constructor, where the name is set and subroutine called Update that will be called when new value of our stock will be set.</p>
<p>Now, that we have an observer, we can create a subject class that will be an abstract class used by our stock.</p>
<pre>Class CObserverSubject
	m_oList List As CObserver

	Sub Attach (observer As CObserver)
	  If (Not Iselement (m_oList (observer.ObserverName))) Then
	     Set m_oList (observer.ObserverName) = observer
	  End If
	End Sub

	Sub Detach (observer As CObserver)
	  If (Iselement (m_oList (observer.ObserverName))) Then
	     Erase m_oList (observer.ObserverName)
	  End If
	End Sub

	Sub Notify ()
		Forall observer In m_oList
			Call observer.Update()
		End Forall
	End Sub
End Class</pre>
<p>The class contains list of all investors (observers) and operations to add (Attach ()) or remove (Detach ()) them. There is also routine Notify, that will update each and every investor.</p>
<p>Framework is now set. Moving on to concrete classes. First, we will create a concrete subject class called ObserverStock.</p>
<pre>Class CObserverStock As CObserverSubject
	m_strName As String
	m_dValue As Double

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

	Property Get Value As Double
		Value = Me.m_dValue
	End Property

	Property Set Value As Double
		Me.m_dValue = Value
		Call Notify()
	End Property

	Sub New (strName As String, dValue As Double)
		Me.m_strName = strName
		Me.m_dValue = dValue
	End Sub
End Class</pre>
<p>The class inherits from ObserverSubject class. Also, it has a property for obtaining stock name and properties for obtaining and setting stock value. However, when setting stock value, not only value is set, but there is also a call to Notify method, specified in ObserverSubject class. This will notify all subscribers of new value.</p>
<p>The only thing missing now is observer concrete class called ObserverInvestors.</p>
<pre>Class CObserverInvestor As CObserver
	m_Stock As CObserverStock

	Property Get Stock As CObserverStock
		Set Stock = Me.m_Stock
	End Property

	Property Set Stock As CObserverStock
		Set Me.m_Stock = Stock
	End Property

	Sub New (strName As String)
	End Sub

	Sub Update()
		Messagebox Me.m_strName &amp; ": " &amp;_
		m_Stock.StockName &amp; " value is " &amp; m_Stock.Value
	End Sub
End Class</pre>
<p>And it is simple enough. It needs a constructor with name as parameter (due to his parent class), a property that ties stock to the class and Update () function that will ideally send an e-mail to investors, but in this case just pops up a message with investor and stock info.</p>
<p><strong>Usage of previous classes</strong></p>
<p>To use previously stated classes, I wrote an agent that will create a stock, add three investors to it, and change value. Then, last observer will be removed from notification list and value will be updated again. When running this agent, you should first get three pop up messages and then only two.</p>
<pre>Sub Initialize
	Dim observer As CObserverInvestor
	Dim stock As CObserverStock

	Set stock = New CObserverStock ("MyStock", 120.0)

	Set observer = New CObserverInvestor ("Investor 1")
	Set observer.Stock = stock
	Call stock.Attach (observer)

	Set observer = New CObserverInvestor ("Investor 2")
	Set observer.Stock = stock
	Call stock.Attach (observer)

	Set observer = New CObserverInvestor ("Investor 3")
	Set observer.Stock = stock
	Call stock.Attach (observer)

	stock.Value = 100.0

	Call stock.Detach (observer)
	stock.Value = 102.5
End Sub</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lotushints.com/2009/02/design-patterns-part-6-observer-pattern/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Web Services on ND8 vs ND7</title>
		<link>http://www.lotushints.com/2009/01/web-services-on-nd8-vs-nd7/</link>
		<comments>http://www.lotushints.com/2009/01/web-services-on-nd8-vs-nd7/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 08:00:21 +0000</pubDate>
		<dc:creator>Vladimir Kocjancic</dc:creator>
				<category><![CDATA[Lotus Domino]]></category>
		<category><![CDATA[Lotus Notes]]></category>
		<category><![CDATA[Object-oriented development]]></category>
		<category><![CDATA[Upgrades]]></category>
		<category><![CDATA[Web services]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[LotusScript]]></category>

		<guid isPermaLink="false">http://www.lotushints.com/?p=160</guid>
		<description><![CDATA[One would think, creating and running web services on ND8 should not be incompatible with ND7 process. Wrong. There are a few quite important differences when creating web services on ND8 instead of ND7. You can now create clients. The one we&#8217;ve all been waiting for since ND7 came out. Web services created/built on ND8 [...]]]></description>
			<content:encoded><![CDATA[<p>One would think, creating and running web services on ND8 should not be incompatible with ND7 process. Wrong. There are a few quite important differences when creating web services on ND8 instead of ND7.</p>
<ol>
<li>You can now create clients. The one we&#8217;ve all been waiting for since ND7 came out.</li>
<li>Web services created/built on ND8 don&#8217;t work on ND7 anymore! So, keep in mind that if you are running web services on ND7, you shouldn&#8217;t upgrade your designer to release 8 just yet.</li>
<li>You can now use Java libraries when creating web services in Java. You couldn&#8217;t in ND7.</li>
<li>You can now have port class defined in a script library when creating web services using LotusScript. This was not possible in ND7.</li>
<li>You can now return empty array. if you wanted to do this in ND7, you had to create a class, containing an array and then return object of that class.</li>
<li>More SOAP error handling elements.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.lotushints.com/2009/01/web-services-on-nd8-vs-nd7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Design patterns &#8211; Part 4: Factory method pattern</title>
		<link>http://www.lotushints.com/2008/12/design-patterns-part-4-factory-method-pattern/</link>
		<comments>http://www.lotushints.com/2008/12/design-patterns-part-4-factory-method-pattern/#comments</comments>
		<pubDate>Mon, 15 Dec 2008 08:00:51 +0000</pubDate>
		<dc:creator>Vladimir Kocjancic</dc:creator>
				<category><![CDATA[Code optimization]]></category>
		<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[Object-oriented development]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[LotusScript]]></category>
		<category><![CDATA[singleton]]></category>

		<guid isPermaLink="false">http://www.lotushints.com/?p=148</guid>
		<description><![CDATA[Factory method pattern definition: The Factory method pattern defines an interface for creating and objects, but lets subclasses to decide which class they will create. Huh? I will try to present this pattern on a simple example. Imagine you work in a company that sales software. However, this software is, due to different laws, different [...]]]></description>
			<content:encoded><![CDATA[<p>Factory method pattern definition:</p>
<blockquote><p>The Factory method pattern defines an interface for creating and objects, but lets subclasses to decide which class they will create.</p></blockquote>
<p><strong>Huh?</strong></p>
<p>I will try to present this pattern on a simple example. Imagine you work in a company that sales software. However, this software is, due to different laws, different for each country/region it is sold in (in our case EU and USA). You have two types of software (Pro and Basic that differ by price and package). You will need to create a single store that will allow users to only buy products from their country.<span id="more-148"></span></p>
<p>First, you can create an abstract class that will represent a product.</p>
<pre>Class CSoftware
	m_strName As String

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

	Sub New
	End Sub

	Sub PreparePackage ()
	End Sub

	Sub PrintPrice ()
	End Sub
End Class</pre>
<p>As you can see, the class itself is pretty simple. It contains a member variable for product name and has two methods that will prepare a package and print it&#8217;s price.<br />
Now (as you need two product types for two countries) you need to create 4 product classes that will inherit from CSoftware class. I will only show you both EU classes as others are pretty self explanatory.</p>
<pre>Class CEUSoftwareBasic As CSoftware
	Sub New
		Me.m_strName = "EU Basic"
	End Sub

	Sub PreparePackage ()
		'TODO: put your code here
	End Sub

	Sub PrintPrice ()
		'TODO: put your code here
	End Sub
End Class

Class CEUSoftwarePro As CSoftware
	Sub New
		Me.m_strName = "EU Pro"
	End Sub

	Sub PreparePackage ()
		'TODO: put your code here
	End Sub

	Sub PrintPrice ()
		'TODO: put your code here
	End Sub
End Class</pre>
<p>There. You are done with products. Now, you need two stores, that will create desired products. But first, you should create an abstract store class.</p>
<pre>Class CSoftwareStore
	Function orderSoftware (swtype As String) As CSoftware
		Dim sw As CSoftware

		Set sw = createSoftwarePackage (swtype)
		Call sw.PreparePackage ()
		Call sw.PrintPrice ()

		Set orderSoftware = sw
	End Function

	Function createSoftwarePackage (swtype As String) As CSoftware
	End Function
End Class</pre>
<p>As you can see, createSoftwarePackage method is empty. This is because createSoftwarePackage differs from store to store. Method orderSoftware, though, is the same for all stores and can be implemented in abstract class.<br />
Now, a source of both stores that inherit from CSoftwareStore.</p>
<pre>Class CEUSoftwareStore As CSoftwareStore
	Function createSoftwarePackage (swtype As String) As CSoftware
		Dim sw As CSoftware

		Select Case (Lcase (swtype))
		Case "basic": Set sw = New CEUSoftwareBasic ()
		Case "pro": Set sw = New CEUSoftwarePro ()
		End Select

		Set createSoftwarePackage = sw
	End Function
End Class

Class CUSASoftwareStore As CSoftwareStore
	Function createSoftwarePackage (swtype As String) As CSoftware
		Dim sw As CSoftware

		Select Case (Lcase (swtype))
		Case "basic": Set sw = New CUSASoftwareBasic ()
		Case "pro": Set sw = New CUSASoftwarePro ()
		End Select

		Set createSoftwarePackage = sw
	End Function
End Class</pre>
<p>Each store creates and returns an object depending on the type we wanted.</p>
<p><strong>But what will that bring me?</strong></p>
<p>You will only have to know which store you need to use and not care about the product returned. That is a job of each separate store. Thus, your code will be easier to read and to maintain.<br />
Pasted below is a sample execution code.</p>
<pre>Sub Initialize
	Dim storeEU As CEUSoftwareStore
	Dim storeUSA As CUSASoftwareStore
	Dim sw As CSoftware

	Set storeEU = New CEUSoftwareStore ()
	Set storeUSA = New CUSASoftwareStore ()

	Set sw = storeEU.orderSoftware ("basic")
	Print "Package: " &amp; sw.ProductName

	Set sw = storeUSA.orderSoftware ("pro")
	Print "Package: " &amp; sw.ProductName
End Sub</pre>
<p>The agent creates both stores and then for each store orders a software. Printed results should be:</p>
<pre>Package: EU Basic
Package: USA Pro</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lotushints.com/2008/12/design-patterns-part-4-factory-method-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Securing Web Services</title>
		<link>http://www.lotushints.com/2008/12/securing-web-services/</link>
		<comments>http://www.lotushints.com/2008/12/securing-web-services/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 08:00:33 +0000</pubDate>
		<dc:creator>Vladimir Kocjancic</dc:creator>
				<category><![CDATA[Intermediate]]></category>
		<category><![CDATA[Lotus Notes]]></category>
		<category><![CDATA[Object-oriented development]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[LotusScript]]></category>
		<category><![CDATA[Web services]]></category>

		<guid isPermaLink="false">http://www.lotushints.com/?p=134</guid>
		<description><![CDATA[Last week I wrote my first web service (yay!). I am not going to write about that, as process of creating web services is nicely described at IBM developerworks. But, back to my service. The service is used to do some work that only my consumer application should be able to do. However, due to [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I wrote my first web service (yay!). I am not going to write about that, as process of creating web services is nicely described at <a href="http://www.ibm.com/developerworks/lotus/library/nd7-webservices/">IBM developerworks</a>. But, back to my service. The service is used to do some work that only my consumer application should be able to do. However, due to nature of it&#8217;s use, it has to be available on public server. It was after I nearly completed it, when I became aware of this issue. <span id="more-134"></span></p>
<p>Lotus Notes offers several security features for Web services (the same as for notes agents). My first thought was to just set people who can run the service, but that failed miserably, as web service consumer (another LN application) now didn&#8217;t see the service it was supposed to consume.</p>
<p>Next idea was to have Web Service Run as web user, but that only caused an error upon saving newly imported consumer code. Thus, Lotus Notes security failed in full (or, I just don&#8217;t know how to use it for Web Services).</p>
<p>Next option was to have my web service request user name and password, but for the life of me, I couldn&#8217;t find any reference as to how I would do that.</p>
<p>So, the only option left, and the easiest one to implement, was to just create a hash string, that web service could check and send it as part of data structure. It works nicely and provides enough security.</p>
<p>I do wonder why all those security options didn&#8217;t work though&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lotushints.com/2008/12/securing-web-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
