Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How is this "pattern" called?

Reply
Thread Tools

How is this "pattern" called?

 
 
markspace
Guest
Posts: n/a
 
      05-18-2012
On 5/18/2012 2:13 PM, Gene Wirchenko wrote:

>
> I have tended to avoid using OOP patterns except for what I came
> up with myself. I did try reading one of the OOP patterns books, but
> ugh!
> ...
> If you *really* need that, fine, but I do not.



To me, this is the key part here. If you actually get the Gang of Four
book on patterns and read it -- and I mean read ALL of it, starting with
the front inside cover -- it says in the *introduction* not to use the
patterns exactly as presented, but to modify them to your particular
requirements. Patterns are there for you to get ideas from, but they
are not laws that must be followed with out deviation. You're still
required to think when using any given pattern.

In addition, with each pattern (that I've read, at least), the GOF
include a list of pro's and con's, and sometimes the cons are quite
surprising. For example the Visitor pattern doesn't work well when the
nodes/tree to traverse under goes lots of changes. The reason is that
the Visitor pattern isolates the implementation for each node, and it
can be a pain to go back into each implementation and add code for each
new type of node. They recommend not using the Visitor pattern at all
in this circumstance. Just use polymorphism and add the visitor API to
each node directly.

*That* is the biggest advantage to patterns and their study, imo. NOT
"rah rah yay patterns" but telling you when using a pattern might leave
you up a creek with no paddle. It allows you to eliminate a broad swath
of design space quickly and points you in a better direction.

 
Reply With Quote
 
 
 
 
Gene Wirchenko
Guest
Posts: n/a
 
      05-18-2012
On Fri, 18 May 2012 14:35:57 -0700, Patricia Shanahan <(E-Mail Removed)>
wrote:

>On 5/18/2012 2:13 PM, Gene Wirchenko wrote:


[snip]

>> With all of the hoopla over OOP patterns, it is difficult for me
>> to tell how much they are really needed.
>>
>> Yes, I go for keeping it fairly simple.

>
>I think a lot depends on the answer to one key question:
>
>What is the cost if this needs to be changed?


Exactly.

>If we are talking about a widely distributed API, where a change will
>break thousands of programs, it is worth doing a lot to minimize the
>risk of incompatible change. If we are talking about code that is used
>in a couple of places in one program, KISS and refactor if necessary.


I quite agree with you.

With the amount of noise over patterns though, you would think
that many people need the patterns. For me, supporting an in-house
application, there is no or little need. I suspect that there are
many in my situation.

Sincerely,

Gene Wirchenko
 
Reply With Quote
 
 
 
 
Arne Vajh°j
Guest
Posts: n/a
 
      05-20-2012
On 5/18/2012 4:53 AM, Stefan Ram wrote:
> In the MVC pattern, I think, M, V, and C should be at least
> one non-innner class each?


Yes.

Although sometimes the V is not a class but JSP/XHTML/FXML.

> I often have seen (possibly, especially in beginner code) a
> coding pattern, where there is only one single non-inner class:
> the model.
>
> The listeners and the view then are embedded into this
> model, possibly, as inner classes. It's not really MVC
> as the observer pattern is not used for decoupling.
>
> So, to code a simple Java-GUI application, one just writes
> a single class with the model and the controllers as inner
> classes and no observer pattern for model-view decoupling.
> Is there a name for this simple design?
>
> What about ╗the bulk-class patternź? Or ╗the naive GUI patternź?


I prefer "the big mess pattern".



Arne


 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      05-20-2012
On 5/18/2012 12:59 PM, Stefan Ram wrote:
> final class Main
> {
> /* model */
>
> final private java.util.Collection<java.awt.Point> collection
> = new java.util.ArrayList<>();
>
> /* view */
>
> Panel panel;
> final private class Panel extends javax.swing.JPanel
> { public Panel()
> { this.setPreferredSize( new java.awt.Dimension( 300, 300 ));
> this.addMouseListener( new MouseListener() ); }
> final @java.lang.Override public void paintComponent
> ( final java.awt.Graphics graphics )
> { super.paintComponent( graphics );
> for( final java.awt.Point point : Main.this.collection )
> graphics.fillRect( point.x, point.y, 4, 4 ); }}
>
> final private class Frame extends javax.swing.JFrame
> { Frame()
> { Main.this.panel = new Panel(); this.add( Main.this.panel );
> this.setDefaultCloseOperation
> ( javax.swing.WindowConstants.DISPOSE_ON_CLOSE );
> this.pack(); this.setVisible( true ); }
> final @java.lang.Override public void dispose(){ super.dispose(); }}
>
> /* controller */
>
> final private class MouseListener extends java.awt.event.MouseAdapter
> { public final void mousePressed
> ( final java.awt.event.MouseEvent mouseEvent )
> { Main.this.collection.add
> ( new java.awt.Point( mouseEvent.getX(), mouseEvent.getY() ));
> Main.this.panel.repaint(); }}
>
> public final java.lang.Runnable buildGui = new java.lang.Runnable()
> { @java.lang.Override public final void run(){ new Frame(); }};
>
> public final void buildGui()
> { java.awt.EventQueue.invokeLater( this.buildGui ); }
>
> public static void main( final java.lang.String args[] )
> { new Main().buildGui(); }}
>
> I do not see a real problem with this style, assuming that
> the assignment at hand was just to write such a simple dot
> paint program.
>
> The inner classes can easily share a common model and
> identifier scope, while at the same time there is some
> reasonable separation between the different concerns
> of the inner classes.
>
> Should it be required later to decouple one of these inner
> classes more than now, this is also possible using a
> refactor that will make it become an outer class or will
> introduce an observer relationship. But should it not
> be required later, no time is wasted now to implement a
> decoupling and separation not needed.


From a theoretical point of view V and C are not part of M.

From the practical point of view the pattern (combined with
your non standard formatting) ensures that it takes 10
times longer to read and understand the code.

Arne



 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      05-20-2012
On 5/18/2012 1:50 PM, Gene Wirchenko wrote:
> On Fri, 18 May 2012 10:03:04 -0600, Jim Janney
> <(E-Mail Removed)> wrote:
>> http://www.velocityreviews.com/forums/(E-Mail Removed)-berlin.de (Stefan Ram) writes:
>>> In the MVC pattern, I think, M, V, and C should be at least
>>> one non-innner class each?
>>>
>>> I often have seen (possibly, especially in beginner code) a
>>> coding pattern, where there is only one single non-inner class:
>>> the model.

>
> Beginner code does tend to be for a small system.
>
>>> The listeners and the view then are embedded into this
>>> model, possibly, as inner classes. It's not really MVC
>>> as the observer pattern is not used for decoupling.
>>>
>>> So, to code a simple Java-GUI application, one just writes
>>> a single class with the model and the controllers as inner
>>> classes and no observer pattern for model-view decoupling.
>>> Is there a name for this simple design?

>
> How about "KISS"?
>
>>> What about ╗the bulk-class patternź? Or ╗the naive GUI patternź?

>>
>> Big Ball of Mud seems to fit:
>>
>> http://laputan.org/mud/

>
> If the ball is not big, then it is a case of KISS or maybe YAGNI.
>
> There is little sense in using large system methodology on a
> small system. (Do watch though that you do not keep adding to a small
> system and switch over to having a large system wihtout realising it.)


True.

But separation of M, V and C seems to become relevant when
passing the 500 LOC mark.

Arne

 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      05-20-2012
On 5/18/2012 5:13 PM, Gene Wirchenko wrote:
> On Fri, 18 May 2012 12:20:11 -0700, markspace<-@.> wrote:
>
>> On 5/18/2012 10:50 AM, Gene Wirchenko wrote:
>>
>>> a case of KISS or maybe YAGNI.

>
>> I like these too; good thoughts.

>
> I have tended to avoid using OOP patterns except for what I came
> up with myself.


That means that either you are absolute brilliant or a fool
not to learn from other.

> I did try reading one of the OOP patterns books, but
> ugh! Some people seem to think that the last thing you should is do
> in OOP is write a statement that actually instantiates an object.
> (Qual horreur!) Instead, you call a factory -- is that it? -- and
> have all sorts of indirection.


????

There are plenty of new'ing in patterns.

Some patterns with the purpose of making the client code
use different implementations use factories. Obviously since
new does not meet the requirement for enabling the use of
different implementations.

> With all of the hoopla over OOP patterns, it is difficult for me
> to tell how much they are really needed.


Almost all Java code uses various well defined patterns. Large parts
of both Java SE and Java EE uses them.

Arne
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      05-20-2012
On 5/18/2012 6:29 PM, Gene Wirchenko wrote:
> With the amount of noise over patterns though, you would think
> that many people need the patterns. For me, supporting an in-house
> application, there is no or little need.


Or you have not realized the need.

Arne
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      05-20-2012
Arne Vajh├Şj wrote:
> Gene Wirchenko wrote:
>> With the amount of noise over patterns though, you would think
>> that many people need the patterns. For me, supporting an in-house
>> application, there is no or little need.

>
> Or you have not realized the need.



Or both of you are looking at it from the wrong perspective.

I would bet that both of you use "patterns" in the larger, non-buzzwordy
sense, that is, you recognize the shape of structures in your model and can
exploit common idioms for common shapes. Both of you appear to be competent
programmers from what this newsgroup shows, and programmers become competent
only if they have that skill.

The argument is over "patterns" in the GoF sense, a highly bureaucratized,
overly-verbose and religiously canonical set of labels and formats to describe
them. But even amidst all the sturm und drang over the latter kind of
patterns, they provide value in a common terminology and informal use. So when
we discuss Visitor or Singleton, we all know what we mean. ("We" being
competent programmers. One occasionally sees posters here who are less
knowledgeable.)

I favor having a library of common pattern labels to facilitate both
communication and program design. No one should think that the list in
GoF-land is exhaustive, and certainly not mandatory. Just because you haven't
used one of the patterns from the Official List doesn't mean you don't need
patterns, or don't use them.

The point of the Official List is to identify some (only some!) of the most
common patterns and get us used to thinking in terms of patterns, not to be
set upon an altar and have thurifers waved at them.

--
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedi.../c/cf/Friz.jpg
 
Reply With Quote
 
Arne Vajh├Şj
Guest
Posts: n/a
 
      05-20-2012
On 5/20/2012 2:34 PM, Lew wrote:
> Arne Vajh├Şj wrote:
>> Gene Wirchenko wrote:
>>> With the amount of noise over patterns though, you would think
>>> that many people need the patterns. For me, supporting an in-house
>>> application, there is no or little need.

>>
>> Or you have not realized the need.

>
> Or both of you are looking at it from the wrong perspective.
>
> I would bet that both of you use "patterns" in the larger, non-buzzwordy
> sense, that is, you recognize the shape of structures in your model and
> can exploit common idioms for common shapes. Both of you appear to be
> competent programmers from what this newsgroup shows, and programmers
> become competent only if they have that skill.
>
> The argument is over "patterns" in the GoF sense, a highly
> bureaucratized, overly-verbose and religiously canonical set of labels
> and formats to describe them. But even amidst all the sturm und drang
> over the latter kind of patterns, they provide value in a common
> terminology and informal use. So when we discuss Visitor or Singleton,
> we all know what we mean. ("We" being competent programmers. One
> occasionally sees posters here who are less knowledgeable.)
>
> I favor having a library of common pattern labels to facilitate both
> communication and program design. No one should think that the list in
> GoF-land is exhaustive, and certainly not mandatory. Just because you
> haven't used one of the patterns from the Official List doesn't mean you
> don't need patterns, or don't use them.
>
> The point of the Official List is to identify some (only some!) of the
> most common patterns and get us used to thinking in terms of patterns,
> not to be set upon an altar and have thurifers waved at them.


????

I don't think anyone suggested to treat patterns religiously. What is
it that you call arguments against something that no one has actually
suggested?

There are no official list. There are multiple lists: GoF which
are somewhat general OOP, specific Java EE etc..

The common terminology is one of the benefits.

The other big benefit is to learn from others experience instead
of spending a decade or more to learn it the hard way. That point
is actual very much emphasized in the GoF book.

Arne


 
Reply With Quote
 
markspace
Guest
Posts: n/a
 
      05-20-2012
On 5/20/2012 11:34 AM, Lew wrote:
> No one should think that the list in
> GoF-land is exhaustive, and certainly not mandatory.



I'm sure no one does. In support of this idea, I'll offer a couple of
good finds by Y.T. First, xUnit Test Patterns by Meszaros, an absolute
seminal work on test patterns for all you TDDers out there.

<http://www.amazon.com/xUnit-Test-Patterns-Refactoring-Code/dp/0131495054>

The other is Refactoring by Martin Fowler. It's organized as patterns
of change, ways that you can modify your code to improve it. The
organization into is useful because it gives each type of change an
distinct and succinct name, which facilitates communication. For
example, several of Fowler's patterns appear on the NetBeans "Refactor"
menu, and do exactly what he describes.

<http://www.amazon.com/Refactoring-Improving-Design-Existing-Code/dp/0201485672>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM



Advertisments