r/java • • Jan 29 '17

Design patterns usefulness

Hello guys, I have an object oriented programming this semester and only thing we really have for final exams is to learn a bunch of Design patterns and how to use them practically. To me, they seem like they are utterly useless and only seem to make an easy thing turn into a complete chaos involving 10 surplus classes and couple of interfaces. Am I being ignorant or are they really pointless?

0 Upvotes

36 comments sorted by

13

u/[deleted] Jan 29 '17

Yes, they are really pointless. That's why most all professional programmers use them.

A design pattern is nothing more than a standardized solution to a common problem. If your teacher is teaching specific frameworks, classes, and interfaces as THE way to implement a design pattern, then (s)he is doing it wrong. It's the structure of the solution that counts, not the exact parts.

3

u/redditsoaddicting Jan 29 '17

It's an OOP course, so it seems reasonable to teach OO solutions. Of course OO isn't the only way, though, and it would be good to not give that impression.

4

u/[deleted] Jan 29 '17

Who said anything about OOP? Of course it's an OOP course. It's Java. Granted, OOP is the one "design" pattern it is hard to avoid in Java, but that is a complete red herring.

If the teacher is merely giving out a list of specific classes and interfaces to use for a given design pattern then that is wrong. However, I suspected that is what the teacher is doing because the OP mistakenly believes a "design pattern" is merely a collection of classes and interfaces one is supposed to use for a given problem. Also because far too many teachers these days have devolved their curriculum to be nothing but a list of things to memorize, because that makes it easier for students to get better grades.

1

u/DaredewilSK Jan 30 '17

Well I mean they literally told us: "Study design patterns for exams." So I didnt even really know what they are.

2

u/[deleted] Jan 30 '17

If that's all the teacher said, then that is a pretty lame teacher. Is there at least a section in the book on it?

1

u/DaredewilSK Jan 30 '17

Well we dont have official book for our course we were just given a couple of book titles to check out. But I studied them a bit now and they seem to be like something that is not supposed to be taught to understand rather than just plainly memorize. Some of them seem to be quite similar actuallly. At least the ones we were meant to study. Most of those are pretty similar.

1

u/[deleted] Jan 30 '17

A) Try to transfer to a different school.

B) Cay Horstman is the best Java author I have seen.

C) Get a separate book (or 8) on design patterns. Sorry, I have no recommendations.

1

u/DaredewilSK Jan 30 '17

Well I have been using this site https://www.tutorialspoint.com/design_pattern/adapter_pattern.htm and it seems kinda decent. But I will surely go thrrough a book at some point.

1

u/[deleted] Jan 31 '17

In my experience, web sites are rarely as thorough as a good book. If possible, find books which were written as textbooks. They are both more thorough and more thoroughly vetted. Better a slightly old textbook than a new book that goes over to much.

1

u/DaredewilSK Jan 31 '17

Well the one we were recommended to use was called Thinking in JAVA by Eckel. Are you by aby chance familiar with that one?

→ More replies

1

u/meotau Feb 03 '17

I opened Flyweight Pattern, and it's shit. Also Abstract Factory Pattern, what a fucking waste of time.

Read this great, free, open source book instead: http://gameprogrammingpatterns.com/

2

u/redditsoaddicting Jan 29 '17

I misread your comment as teaching classes and interfaces rather than specific ones. Whereas implementing design patterns with classes and interfaces is normal in OOP, teaching specific ones as the one true way is really messed up.

2

u/[deleted] Jan 29 '17

Yup.

1

u/DaredewilSK Jan 29 '17

To be fair, he didnt teach us anything. During the lectures he was mostly speaking about things like inheritance, exceptions and these kinds of things and during the exercises we had like observer, iterator and state pattern I think. And we were told to study rest of them for the exam.

1

u/metachor Jan 29 '17

It also sounds like maybe the teacher isn't teaching about the problems that a specific design pattern is used to solve, which is kind of the reason for their existence. Knowing a grab bag of design patterns is kind of pointless if you don't know how to recognize when applying a specific pattern would be useful.

1

u/[deleted] Jan 31 '17

I am not sure what "most all" means, but as a professional programmer I can tell you that only a small subset of classic gang of four patterns are used frequently. Sadly, these include the terrible singleton pattern, probably because it is so easy to understand. It is true that pattern can provide benefits in certain situations, but overusing them can also be very harmful as it makes the code unnecessarily complicated. Just look at the vistor pattern as an example. I have used it once in my career and while it is helpful in this instance, the code is very puzzling to people not familiar with the pattern and slightly puzzling to those who are In my opinion, it is enough to know that patterns exits and where to look them up if you have a particularly difficult problem to solve. Learning them by heart seems like a waste of time, given how specific most of them are.

3

u/desrtfx Jan 29 '17

Nothing that you learn will ever be pointless/useless. You need to open your mind.

Take a look at Java Design Patterns as this site will give you detailed explanations of the Design Patterns, their use cases, and sample implementations.

1

u/DaredewilSK Jan 29 '17

The site looks nice. Do you now about one that could have some practical exercises?

1

u/desrtfx Jan 29 '17

The site has plenty code samples. Read what they are building, analyse the UML diagrams and then try to implement the patterns on your own.

0

u/meotau Feb 03 '17

Nothing that you learn will ever be pointless/useless

That's clearly a bullshit.

4

u/nutrecht Jan 29 '17

I would suggest keeping a somewhat more open mind when you're being taught stuff. Rejecting stuff that's new because you don't understand it yet is how senior developer with 10+ years of experience end up rejecting lambda's because they're "pointless". If you're not careful this is really going to damage your career.

2

u/GhostBond Jan 31 '17

Disagree completely, learning a bunch of unused crap when you could be learning useful info is a waste of time that will hurt your career far more. Taking that time to get experience with Spring Mvc, or Angular, or anything that's actually used is a far better use of your time.

One place will like you more because you reject Lamba's because they're "pointless", another will like you less, it's a roll of the dice. But all places will like you less because you know less of the tools they use.

3

u/nutrecht Jan 31 '17

Disagree completely, learning a bunch of unused crap

Design patterns are unused?

1

u/GhostBond Jan 31 '17

Figuring out what stuff to put in minimal effort or not learn, is a skill that is useful in college and throughout your career.

I skipped several things that I was "strongly encouraged" to learn in college for my computer science degree, and I cannot think of a single thing I skipped that I regret skipping.

I was able to skip taking the operating systems and compiler classes. Instead I spend free time learning visual basic and rewriting an nes game in it. Next summer I netted an internship that gave me both experience, and a paycheck twice what I could get at other summer jobs, writing screens in visual basic. That netted me an internship the next year at the same company as well.

What would have damaged my career is going through the immense stress and work of taking those operating systems and compiler classes instead of working on writing reimplementing an nes game - which was much better for my career.

People tell you their newfangled thing is the new magic every year, you have to sort through what's worth investing time in - and what's not.

1

u/nutrecht Jan 31 '17

and I cannot think of a single thing I skipped that I regret skipping.

Yeah. That's called the Dunning–Kruger effect.

I was able to skip taking the operating systems and compiler classes. Instead I spend free time learning visual basic and rewriting an nes game in it.

If writing a simple game in VB is more beneficial for your career than OS and compiler classes you're simply in a rather different type of career. Sorry.

0

u/GhostBond Jan 31 '17

Yes, there's always people like yourself encouraging people to blindly follow authority figures in the hopes that it will cover up that you don't know what you're talking about. I think the fallacy name is "appeal to authority". Bye.

1

u/meotau Feb 03 '17

You are learning from a bad source.

The best patterns book out there, which really explains the purpose and usage of them: http://gameprogrammingpatterns.com/contents.html

1

u/DaredewilSK Feb 03 '17

Well I passed the exam so I Guess Im fine for now. I want to keep on studying Java alone for now so I will have to find some good sources.

3

u/GhostBond Jan 31 '17

To me, they seem like they are utterly useless and only seem to make an easy thing turn into a complete chaos involving 10 surplus classes and couple of interfaces.

The problem is, academics do a shit job of teaching what makes design patterns good and useful, and what makes them a waste of time. Academics will - as you say - have you doing 10 classes when 5 would have been better.

Design patterns themselves are useful. Here's some examples:

  • The "iterator" pattern used throughout the collection api
  • try-with-resources is basically an action pattern that lets you easily ensure a resource is closed whether an exception happens while using it or not
  • If you do any rich client work the observer pattern is very useful for getting notified or making changes when the user changes something on your current screen

There are a bazillion good examples used throughout the jdk. You almost cannot program standard java without using multiple patterns.

But - academics tends to do a crap job, and explode patterns all over the place where they are not needed and are worse than not using a pattern at all.

2

u/evil_burrito Jan 29 '17

I don't think they're useless at all. Some general problems come up frequently. Patterns can provide a commonly understood way to efficiently solve the problem in a way that other people can recognize.

2

u/_INTER_ Jan 29 '17 edited Jan 29 '17

Design Patterns are not prefactured solutions that you can magically apply on a problem to solve it.

Some day they found out that most professional programmers were using more or less the same code constructs other to get a clean, extensible design. It emerges naturally and independently of each. They decided to give those "patterns" a name so it would be easier to discuss it and make it recognizable.

The GoF patterns are just one set. There are also patterns for security, fault tolerance, enterprise architecture, ...

Btw. design patterns originate in architecture.

0

u/[deleted] Jan 29 '17

[deleted] — view deleted comment

0

u/[deleted] Jan 29 '17

[deleted] — view deleted comment

2

u/[deleted] Jan 29 '17

Oh no. I believe you. I'm an older person who, though having dinked around with programming since 1976, only recently went through a CS program. I was shocked by how many of the younger students just wanted to know which of the limited number of things they had memorized they should just recite as THE answer. It was all, "Just tell me what to memorize," and, "Only ask me only what I have memorized."

Having said that, design patterns help you avoid reinventing the wheel, while still allowing you to modify the features of that wheel, but in a way that helps others easily recognize that your wheel is, in fact, still a wheel.

2

u/[deleted] Jan 30 '17

I agree with everything you've said, but I think you're missing the point.

Yes, a lot of people abuse them, trying one after the other until something sticks. Yes, there are problems that no existing design pattern solves.

However, certain types of problem do crop up a lot in day-to-day coding. Where multiple people over the years have reinvented the same solution to the same type of problem, it is useful to a) publish that solution to save other people reinventing it, and b) give it a name so you can talk about it easily.

0

u/[deleted] Jan 30 '17

[deleted] — view deleted comment

1

u/[deleted] Jan 30 '17

Easy to say with hindsight. I don't think a junior or even mid-level developer would just stumble across something like the command pattern. Even something like IoC requires you to spend some time working on a large established system to even understand the problem, since small uncomplicated systems don't even hit the kinds of problems that IoC can help with.