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 4 2614
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/44f79c1def2583ca/200adefeefa5f3fa?lnk=st&q=design+pattern+builder+p yth
on+-build&rnum=25#200adefeefa5f3fa 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
> 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 :-)
I have converted another example of strategy which I prefer to the 2
described earlier, here it is:
class FindMinima:
def algorithm(self):raise NotImplementedError
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 ConjugateGradient (FindMinima):
def algorithm(self,line):
return (3.3,4.4)
class MinimaSolver: # context class
strategy=''
def __init__ (self,strategy):
self.strategy=strategy
def minima(self,line):
return self.strategy.algorithm(line)
def changeAlgorithm(self,newAlgorithm):
self.strategy = newAlgorithm
def test():
solver=MinimaSolver(LeastSquares())
print solver.minima((5.5,5.5))
solver.changeAlgorithm(Bisection())
print solver.minima((5.5,5.5))
test()
> I have converted another example of strategy which I prefer to the 2 described earlier, here it is:
class FindMinima: ********def algorithm(self):raise NotImplementedError
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(line):
return 1.1, 2.2
def newtons_method(line):
return 3.3, 4.4
def bisection(line):
return 5.5, 6.6
def conjugate_gradient(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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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.
...
|
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...
|
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...
|
by: sicapitan |
last post by:
FYI,
with something like this:
hotelement = "hotelement"+hotcount;
hotspot = Builder.node('div', { id:'hotspot'+hotcount,
className:'hotspot', style:''+divstyle }, )
]);
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |