473,770 Members | 6,713 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Builder Pattern

Hi

I really need an example of a builder pattern in python, the closest I
could find to something resembling builder was on this thread...
http://groups.google.co.uk/group/it....0adefeefa5f3fa

Unfortunately I can't read the discussion it's possibly in Spanish.

Does anyone know of a builder example for python? Thanking you in
advance for your help.

Jason

Jan 29 '06 #1
4 2626
Jason <su*****@gmail. com> wrote:
Hi

I really need an example of a builder pattern in python, the closest I
could find to something resembling builder was on this thread...
http://groups.google.co.uk/group/it....e_thread/threa
d/44f79c1def2583c a/200adefeefa5f3f a?lnk=st&q=desi gn+pattern+buil der+pyth
on+-build&rnum=25#2 00adefeefa5f3fa
Unfortunately I can't read the discussion it's possibly in Spanish.
No, the leading 'it' in the newsgroup name means 'italian'. I was one
of the discussants.
Does anyone know of a builder example for python? Thanking you in
advance for your help.


The *example* is right there, e.g. at
<http://groups.google.co.uk/group/it....4edfee13b6fb51
6f> for the Python translation of the example found at a URL quoted in
the same post. If you want an EXAMPLE, there it is -- it's all code, no
comments, so the fact that the following discussion is in Italian should
be irrelevant, no?

What the following discussion says is that the C++ -> Python
transliteration is totally trivial and obvious and berates the original
requestor for making me waste 10 minutes to provide it.
Alex
Jan 29 '06 #2
> What the following discussion says is that the C++ -> Python
transliteration is totally trivial and obvious and berates the original
requestor for making me waste 10 minutes to provide it.


Thanks for the giggle :-)

Jan 29 '06 #3
I have converted another example of strategy which I prefer to the 2
described earlier, here it is:

class FindMinima:
def algorithm(self) :raise NotImplementedE rror
class LeastSquares (FindMinima):
def algorithm(self, line):
return (1.1,2.2)
class NewtonsMethod (FindMinima):
def algorithm(self, line):
return (3.3,4.4)

class Bisection (FindMinima):
def algorithm(self, line):
return (5.5,6.6)

class ConjugateGradie nt (FindMinima):
def algorithm(self, line):
return (3.3,4.4)

class MinimaSolver: # context class
strategy=''
def __init__ (self,strategy) :
self.strategy=s trategy

def minima(self,lin e):
return self.strategy.a lgorithm(line)

def changeAlgorithm (self,newAlgori thm):
self.strategy = newAlgorithm

def test():
solver=MinimaSo lver(LeastSquar es())
print solver.minima(( 5.5,5.5))
solver.changeAl gorithm(Bisecti on())
print solver.minima(( 5.5,5.5))
test()

Feb 2 '06 #4
> I have converted another example of strategy which I prefer to the 2
described earlier, here it is:

class FindMinima:
********def algorithm(self) :raise NotImplementedE rror


When most of your code does nothing in a pompous way that is a sure sign
that you are heading in the wrong direction. Here's a translation into
python:

def least_squares(l ine):
return 1.1, 2.2

def newtons_method( line):
return 3.3, 4.4

def bisection(line) :
return 5.5, 6.6

def conjugate_gradi ent(line):
return 3.3, 4.4

def test():
solver = least_squares
print solver((5.5,5.5 ))
solver = bisection
print solver((5.5,5.5 ))

test()

Peter
Feb 2 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
12337
by: Anand K Rayudu | last post by:
Hi All, I am new to python & want to build some GUI dialogs. Can some one please suggest some document reference. I am hoping that standard python install will have some GUI development modules & GUI builder in built. I have python 2.3.3. Can some one please suggest
2
3489
by: qazmlp | last post by:
Builder pattern seem to suit my requirements perfectly except in one case as described below. I have used the same example diagram that is used in GOF Design pattern book, to explain the problem that I am facing. aClient aDirector aConcreteBuilder =============================================================================
0
3112
by: Xproblem | last post by:
FTP Client Engine for C/C++ 2.4 Screenshot - Soft.comFTP Client Engine for C/C++ 2.4. ... System Requirements: Windows C/C++ compiler - Microsoft operating system: Windows 95, Windows 98, Windows ME, ... www.soft30.com/screen-70-11625.htm - 31k - Cached - Similar pages C++ Server Pages 1.6 - Soft.comC++ Server Pages (CSP) allows developers to build Dynamic Web Pages and Web ... Existing C++ projects can be ported to the Web by simply...
2
7370
by: Mike Turco | last post by:
I like using the expression builder for a lot of different things but it isn't always available when I want to use it, for example in the code window, or in all of the control properties. I am usually stuck having to go into the database window, creating a new query, etc., and then right-clicking in a field and selecting build. Is there a shortcut key, a way to add a button to an Access toolbar, or something like that so I can use to...
18
2165
by: ILCSP | last post by:
Hi, I just started learning Visual Basic (VB.NET 03) and I need to do this small program that will read a text file we get from another company that has survey data, parse it and flatten it out and make single strings out of the records in it. The major difference between this space delimited file from the many examples in these groups is that the data is not presented horizontally, but vertically. You can see an example below. What I...
0
1719
by: FluffyCat | last post by:
Last fall I started a series of design pattern examples using PHP5. I think the last pattern I did was the Singleton in January. Getting back to it here is my first cut at the Builder pattern. http://www.fluffycat.com/PHP-Design-Patterns-Builder/ In the builder pattern a director and builder work togther to build an object. The director controls the building and specifies any variations that can be done with the object. The builder...
2
2301
by: Mike | last post by:
Hello NG, i am just learning various Design Patterns and now i am not sure, if this design is correct (Builder) or if i should use an other pattern. I have various classes (here ChildA and ChildB) derived from class Base. Now i want to create an object, but i don't want to know which class to instantiate.
1
1748
by: David Bellot | last post by:
Hi, if I consider the Factory Method design pattern, then I should have the following objects: Object and ObjectFactory which are usually abstract classes Then for each subclasses like ConcreteObject1, ConcreteObject2, .... I must have a ConcreteObjectFactory1, ConcreteObjectFactory1, ...
2
3876
by: sicapitan | last post by:
FYI, with something like this: hotelement = "hotelement"+hotcount; hotspot = Builder.node('div', { id:'hotspot'+hotcount, className:'hotspot', style:''+divstyle }, ) ]);
0
10225
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10001
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8880
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3573
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.