From asheesh at asheesh.org Thu Nov 3 11:20:07 2005 From: asheesh at asheesh.org (Asheesh Laroia) Date: Thu, 3 Nov 2005 11:20:07 -0500 (EST) Subject: [Patterns] Visitor pattern Message-ID: I'm looking at some basic Visitor design pattern code as part of this OOSE homework assignment. I would like to share it, and then a comment I have. Source: http://ootips.org/visitor-pattern.html package Transactions; public class Transaction { public abstract void accept(TransactionVisitor v); } interface TransactionVisitor { public void visit(DepositTransaction dt); public void visit(WithdrawlTransaction wt); } class DepositTransaction extends Transaction { public void accept(TransactionVisitor v) {v.visit(this);} } class WithdrawlTransaction extends Transaction { public void accept(TransactionVisitor v) {v.visit(this);} } class TransactionUIFactory implements TransactionVisitor { private UI itsUI; public UI getUI() {return itsUI;} public void visit(DepositTransaction dt) { itsUI = new DepositUI(dt); } public void visit(WithdrawlTransaction wt) { itsUI = new WithdrawlUI(wt); } } My reaction: "How dumb!" What this *should* be is a simple mapping of class type -> class constructor. So screw this dumb overloading junk. Just make a HashTable or Dictionary or whatever that maps class types to class constructor. Then we turn TransactionUIFactory into: class TransactionUIFactory implements TransactionVisitor { private UI itsUI; public UI getUI() {return itsUI;} public Hash mapping = {DepositTransaction: DepositUI, WithdrawalTransaction: WithdrawalUI}; public void visit(Transaction t) { itsUI = new mapping[Transaction.type](t); } } Advantage of my code: The code is easier to read and has less duplication. What's that, you can't do that in your dumb languages like Java or C#? You sure can in Python. I see no reason you couldn't do it in LISP (or CLOS, Object-Oriented LISP, as Peter would remind me to mention and then cringe at the mention of). And people tell me Java is object-oriented. /me shakes his head This is what I mean when I say the braindead uselessness of these languages makes you NEED many of our design patterns as a series of complex workarounds. Surely there *are* interesting and worthwhile design patterns. But when I see them used as crutches for missing features in these so-called object-oriented languages it makes me want to shoot someone. This is hardly a visitor now; there's no explicit double dispatch. It's just a regular-old boring function that takes some class in and returns some other class instance. Moral of the story: There is a floor for how much duplication of code you have to have in every language. One reason I prefer Python to Java because that floor is lower. (And the kids these days seem to think Java is good. Brendan, I'm looking straight at you.) You are all free to take off your flame-retardant suits now. -- Asheesh. -- Some people have no respect for age unless it's bottled. From phf at cs.jhu.edu Fri Nov 4 02:36:25 2005 From: phf at cs.jhu.edu (=?ISO-8859-1?Q?Peter_Fr=F6hlich?=) Date: Fri, 04 Nov 2005 02:36:25 -0500 Subject: [Patterns] Visitor pattern In-Reply-To: References: Message-ID: <0062974055295b3f17572fd64eda2e78@cs.jhu.edu> Hi all, On Nov 3, 2005, at 11:20, Asheesh Laroia wrote: > What's that, you can't do that in your dumb languages like Java or C#? > You sure can in Python. I see no reason you couldn't do it in LISP (or > CLOS, Object-Oriented LISP, as Peter would remind me to mention and > then > cringe at the mention of). I hope I never really brought up CLOS? :-) > And people tell me Java is object-oriented. /me shakes his head Well, the debate of what exactly "object-oriented" is has been raging for years. Actually it died down in the mid-to-late-nineties when most people settled on Peter Wegner's formula. I disagree with his, I don't think inheritance is a central feature. You seem to fall on the other side, thinking that lots of dynamism is essential. For me that's not an OO issue, just a language issue. > This is what I mean when I say the braindead uselessness of these > languages makes you NEED many of our design patterns as a series of > complex workarounds. Surely there *are* interesting and worthwhile > design > patterns. But when I see them used as crutches for missing features in > these so-called object-oriented languages it makes me want to shoot > someone. Whoa... :-) The GoF is quite explicit in the book that some design patterns are "non-patterns" in certain languages, and they make the point by stating that in C even "inheritance" would be a pattern (if it were used widely that is). In fact, lots of people have gotten PhDs for the following research approach: (1) look at design patterns that are neat, (2) look at languages that need them, (3) extend those languages with features that make the design patterns go away (if the feature is used correctly). I'll try to include one of these discussions in the list of papers to look at for the last few meetings. > You are all free to take off your flame-retardant suits now. I think we should rather put them on and make sure that they're sealed tightly. :-) Peter -- Peter H. Froehlich <><><><><><> http://www.cs.jhu.edu/~phf/ OpenPGP: ABC2 9BCC 1445 86E9 4D59 F532 A8B2 BFAE 342B E9D9 From phf at cs.jhu.edu Wed Nov 16 16:51:30 2005 From: phf at cs.jhu.edu (Peter Froehlich) Date: Wed, 16 Nov 2005 16:51:30 -0500 Subject: [Patterns] Oops... Message-ID: <6ec6fb2cf611a16923e16197fd291d05@cs.jhu.edu> Hi all, The reminder just popped up and I realized that I never posted a paper to read. Darn! So I'll come over to the room to tell you all the sad story and then that's that. :-/ Peter -- Peter H. Froehlich <><><><><><> http://www.cs.jhu.edu/~phf/ OpenPGP: ABC2 9BCC 1445 86E9 4D59 F532 A8B2 BFAE 342B E9D9 From asheesh at asheesh.org Wed Nov 30 01:35:57 2005 From: asheesh at asheesh.org (Asheesh Laroia) Date: Wed, 30 Nov 2005 01:35:57 -0500 (EST) Subject: [Patterns] Hey now, everybody now Message-ID: Peter, want to give us some reading? -- Asheesh. -- If we were meant to get up early, God would have created us with alarm clocks. From phf at cs.jhu.edu Wed Nov 30 11:30:13 2005 From: phf at cs.jhu.edu (=?ISO-8859-1?Q?Peter_Fr=F6hlich?=) Date: Wed, 30 Nov 2005 11:30:13 -0500 Subject: [Patterns] Hey now, everybody now In-Reply-To: References: Message-ID: <86d502c308d16f332a1f49c89250519c@cs.jhu.edu> Hi all, On Nov 30, 2005, at 01:35, Asheesh Laroia wrote: > Peter, want to give us some reading? I suck! Yesterday I ran into Promit and he reminded me as well, but I can't keep my wits about me as I am trying to write a simple 3D engine for the foundations course. :-/ Alright, so here's the first paper I thought of: http://portal.acm.org/citation.cfm?doid=286936.286952 It's somewhat "controversial" and maybe not written in the best English possible, but still interesting. Another interesting one is here: http://www.ccs.neu.edu/home/lorenz/papers/oopsla97/ Then there's the whole business about "meta patterns" that Wolfgang Pree started in 1994 or so, but no "official" copy of his papers seems to survive online right now. This one is just as good however: http://www.exciton.cs.rice.edu/comp410/frameworks/Pree/C010.pdf I suggest we focus on the first paper and try to dissect/understand what they are saying and how much impact that has, but feel free to read the other two as well (if they strike you as more interesting). Peter -- Peter H. Froehlich <><><><><><> http://www.cs.jhu.edu/~phf/ OpenPGP: ABC2 9BCC 1445 86E9 4D59 F532 A8B2 BFAE 342B E9D9 From ussjoin at acm.jhu.edu Wed Nov 30 18:33:23 2005 From: ussjoin at acm.jhu.edu (Brendan O'Connor) Date: Wed, 30 Nov 2005 18:33:23 -0500 Subject: [Patterns] (no subject) Message-ID: <438E36C3.8090600@acm.jhu.edu> http://www.daimi.au.dk/~apaipi/workshop/master.pdf Is the thesis. ---BFO From phf at cs.jhu.edu Wed Nov 30 18:58:08 2005 From: phf at cs.jhu.edu (Peter Froehlich) Date: Wed, 30 Nov 2005 18:58:08 -0500 Subject: [Patterns] (no subject) In-Reply-To: <438E36C3.8090600@acm.jhu.edu> References: <438E36C3.8090600@acm.jhu.edu> Message-ID: <6a63aaf14c6bebeab70852eb410cc388@cs.jhu.edu> Hi all, On Nov 30, 2005, at 18:33, Brendan O'Connor wrote: > http://www.daimi.au.dk/~apaipi/workshop/master.pdf > Is the thesis. Thanks, material for a whole semester... :-) Asheesh probably likes this one, although I don't know where to find more information: http://dx.doi.org/10.1145/289423.289478 Peter -- Peter H. Froehlich <><><><><><> http://www.cs.jhu.edu/~phf/ OpenPGP: ABC2 9BCC 1445 86E9 4D59 F532 A8B2 BFAE 342B E9D9