Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I study computer science and I have a class called "Programming Techniques". Its purpose is to teach (us) good object oriented design principles. During the semester we have homeworks, programs that we must write to demonstrate what we've learned.

The lab assistant demands for each of these homeworks that specific design patterns should be used. For example, the current homework is an application used for processing customer orders. We are demanded to use either "Factory Method" or "Abstract Factory" design patterns for this. It gets even worse: at the end of the semester we must write a program (something more complex) that must use at least one creational pattern, at least one structural pattern and at least one behavioural pattern.

Is it normal to demand this ? I mean, forcing us to design our programs in such a way that a specific design pattern makes sense is just beyond what I consider ok. If I'm a car mechanic and have a huge tool box, then I will use a certain tool from that box if and when the situation demands it. Not more, not less. If my design of the application doesn't demand at all the use of "Abstract Factory" (for example), then why should I implement it ?

I'm not sure yet if the senior lecturer agrees with what the lab assistant is demanding, but I want to talk to him about it and I need solid arguments to do so. How should I approach this problem with him ?

PS: I'm sure there must be a better way to teach us these things. Maybe making us each week read about 3 design patterns and the next week giving us a test with small but specific programming or architectural situations/problems. The goal in that test would be to identify what design patterns would make sense and how they could be implemented. This way, he can see if we understand them.

EDIT: These homeworks are not just 100-line programs, they have quite a lot of requirements and are fairly complicated. This is the reason we have about 2 - 3 weeks of deadline for each of them.

I agree that practicing this is the best way to learn. But shouldn't smaller programs/applications be used for this ? Something just for demonstrating purposes. Not big programs with lots of requirements/classes/etc.

share|improve this question
53  
You are at university/college - you do what your lecturer/teacher demands otherwise you don't pass the course. –  ChrisF Mar 23 '12 at 13:29
2  
By default, follow ChrisF advice ;) After your studies, you will do exactly what you want.... or not... depending on your boss ;) –  user2567 Mar 23 '12 at 13:33
4  
I will admit that it does sound odd if you are being asked to use inappropriate design patterns or too many design patterns, but reading your first paragraph again it sounds like you are just being asked to use one or two specific patterns or class of pattern. Any reasonably complex program will have several design patterns implemented. –  ChrisF Mar 23 '12 at 13:37
2  
@SoboLAN - I'll second what ChrisF is saying. Using "at least one creational pattern, at least one structural pattern and at least one behavioural pattern" is not much; if you weren't using at least that, you could almost say that your program was devoid of design patterns. –  Daniel B Mar 23 '12 at 13:39
7  
It will give you something to think about while you're working on your first job maintaining ancient code where no coherent pattern was used or while writing simple CRUD or reporting apps. –  jfrankcarr Mar 23 '12 at 13:59

10 Answers 10

up vote 88 down vote accepted

Sorry, but I think your teachers are right.

If you were developing software for a customer, and the customer or your boss requires you to use specific design patterns, I would definitely say that that was a big mistake. But there is a difference between class assignments and software development for a customer: both serve completely different purposes:

  1. If you are developing for a customer, the purpose is the software you create. It should work, it should be maintainable, it should satisfy your customer's requirements.

  2. The purpose of your assignments is not the software you create, it is the experience you gather during the whole creation process. During the assignment you will learn things about implementing patterns, which will help you understand how the patterns work, when to use a pattern, and (hopefully) when not to use it, as well.

To use your car mechanic analogy: You are not a mechanic, you are learning how to become one. And maybe your teacher will tell you which wrench to use, in order to change the tires. That is completely ok. And if the owner of the garage tells you to change the tires with a screwdriver, because he wants you to learn something from the failure that will certainly occur, that is ok, too.

share|improve this answer
7  
I like your continuation with the car mechanic analogy. Nice answer, thank you. –  Radu Murzea Mar 23 '12 at 16:37
1  
Using the analogy, I would however be very concerned if the owner of the garage expected you to succeed with the screwdriver... @SoboLAN - since you accepted this, I guess that's not what you meant in the question? ('Tis how I read it) –  Izkata Mar 23 '12 at 19:13
    
@Izkata I accepted this because I realised he was right. I was assuming my teacher(s) was/were exagerating. It was a wrong assumption... –  Radu Murzea Mar 23 '12 at 20:17
    
Why the customer would require to use a specific Design Pattern (DP)? Also I wouldn't like to work for a boss who messes with my design decisions. BTW, DP are not used in advanced, but after realizing that there are code smells. –  faif Mar 23 '12 at 22:13
1  
@faif: Why, indeed, would he? I have no idea, but it did happen to a colleague of mine... and I disagree with the second part of your comment: DP should be used when they bring a benefit. That can be as early as in the initial design phase, long before any 'code smells' develop, because there is no code yet. –  Treb Mar 24 '12 at 15:48

If you feel your teacher is doing something wrong, discuss it with him or her.

Imposing specific practices in an homework is very common. It helps you learn the thing much better than just reading about it. In short, practice is an essential learning step.

I hear and I forget. I see and I remember. I do and I understand. [Confucius]

share|improve this answer
    
Since this is the winningnest answer, I want to feature and enhance some additional points made below: If the assignments you are given are programs that call for the design pattern requested, and I would hope/assume they are, then the TA may just be trying to give you a leg up. Although a better way may be to let you all code it up and ask you to change it so that it breaks unless you had implemented the pattern, or show you how easy it was had you used it. –  Joshua Drake Mar 23 '12 at 14:43
    
Too often people force patterns, when instead they should should first determine the patterns fitness for their problem, but from your description I do not believe that to be the case. –  Joshua Drake Mar 23 '12 at 14:44

you used a mechanic example so lets try to stay with that. When the mechanic was in training and they were teaching tire replacement they told him to use the lug wrench, they didn't hand him a tool box and say go. Its the same with you, you are in classes to learn to implement these techniques so when a programming assignment is intended to use a certain tool they tell you. This problem is not really a problem, unless they are telling you to use a hammer on those screws.

share|improve this answer

Is the point of the class/exercises to learn design patterns? If yes, then do what he says and work on learning the design patterns. Don't focus on the fact that the pattern is ill-suited to the sample project.

If the class/exercise is about choosing the right design pattern for the right situation, then you might have an acceptable complaint and can talk with your teacher about it. It would be even better if you can suggest some good sample projects that would benefit from the design pattern you're trying to learn.

Just don't forget to be respectful and accept the fact that your teacher might not be able to change the program.

share|improve this answer

Firstly, is this an excellent way of teaching design patterns? No, probably not. Is there a better way to teach them? I'm sure there is. Should you be organising a revolt because of this? Absolutely not. Let me elaborate:

You are in a class which seems to be dealing heavily with design patterns. Design patterns are your "software engineering toolbox", and you should definitely get very familiar with them. In general, they have many positive aspects, and one of those is that they allow you to think on a higher level of abstraction. Instead of trying to explain things on the level of individual methods or variables, you now think in terms of high level patterns.

It gets even worse: at the end of the semester we must write a program (something more complex) that must use at least one creational pattern, at least one structural pattern and at least one behavioural pattern.

You make this sound like it's a bad thing. Yes, there are some people who go pattern-crazy, and use them inappropriately and over-complicate everything with them. One creational pattern, one structural pattern, and one behavioural pattern is not it. Any non-trivial system will have at least this much, so it's a good idea to get comfortable with them. I suspect this is the general idea in your class - you should give it another shot.

share|improve this answer
1  
I thought it was the case of "some people who go pattern-crazy". It turns out I only miscalculated where that line is. PS: I did get maximum grades so far, hopefully it'll continue to work :) . –  Radu Murzea Mar 23 '12 at 14:53
    
@SoboLAN - I thought that might have been the case :) Outside of university, creational patterns tend to be dictated by your team's standards or the the ORM you choose, and behavioural patterns like Iterator and Strategy go without saying. When it comes to structural patterns, Adapters, Bridges, Composites are also plentiful. Dealing with an average system (which is often hundred thousands of lines of code), you will run into dozens of patterns. That's why it's good to know them like the back of your hand; the fact that they are teaching them at university is a good thing :) –  Daniel B Mar 24 '12 at 8:41
    
@DanielB - I have reasons to believe that I will be facing something similar to SoboLAN regarding the end-semester project.. By looking on the project assignments from the previous years I can see that it is stated that the grading will be done based on how many design patterns are used throughout the project. What's your view on this way of grading? –  Mihai Bişog Mar 12 '13 at 17:34
    
@MihaiBişog It sounds a bit misguided; I'd prefer testing for actual, deep understanding of (some) patterns, and ability to correctly identify cases where it's beneficial to use them. I guess this is much harder to test for, however, which probably leads to the simpler approach of just counting the patterns. As I mentioned to SoboLAN however, in environments where patterns are heavily used, they become part of the language of the team, and you won't even notice when you encounter them. I guess these types of classes try to prepare you for that in some way. –  Daniel B Mar 13 '13 at 5:16
    
@MihaiBişog also, when patterns are taught at universities, they are often synonymous with GoF patterns, which are just a tiny subset of patterns that exist. I'm also not a big fan of rote memorisation of things, the main use of patterns for me is as a communication mechanism - often you'll encounter a class whose name or implementation lets you recognise the pattern(s) it uses, allowing you to safely guess at it's workings and design. When you use them in your code, you also afford others this luxury, of course, they also have to understand "patterns" for this to actually work. –  Daniel B Mar 13 '13 at 5:23

It does sounds strange that there making you come up with your own assignments to create specific patterns, however, if you can pull it off I would recommend that you embrace the class and do it. It'll be a great learning experience and an extremely great thing to put on your resume. Being a college grad in the real world I can tell you that that last point I made makes all the difference in the world if you ever want to get a job in this field. A degree alone means nothing without the work to back it up.

share|improve this answer

I agree that practicing this is the best way to learn. But shouldn't smaller programs/applications be used for this ? Something just for demonstrating purposes. Not big programs with lots of requirements/classes/etc.

Design patterns really aren't that interesting in a very small program. Anybody can implement a factory or an observer for a class that doesn't do anything useful. The power of patterns comes from their ability to help you organize larger programs -- once you recognize that a pattern is being used, you don't have to read through the entire implementation to have a pretty good idea of what the code does. Patterns are the tools that you use to translate "lots of requirements" into sensible classes. So asking you to use the patterns that you're learning in the context of a program that does something interesting seems like a pretty good idea.

Besides, if you're writing these programs as homework over 2-3 weeks, you're definitely still writing small programs.

share|improve this answer

It's sad if university is just about passing the subject these days regardless of what or how you learn. I feel for you because a few years ago I was in a similar situation, but I was given a specific project to implement where a factory was utterly irrelevant, but nevertheless we had to force one in. The problem with this kind of teaching is that it is very misleading to impressionable students. If teachings patterns out of context, teachers must make that point clear. Any good student should raise his concerns to the teacher...it's what learning should be about.

share|improve this answer

You are in university? I hardly see the problem. I'm finishing my last year of high school and my CS teacher has always given us these kind of assignments throughout the whole semester each year I took his course. Even now, he gave us 2 weeks to finish an oop assignment, something I'm working with for the first time. Just like in your case, it's not a 100 line program but don't guage difficulty based on lines of code. Sometimes it's outright a difficult task, other times it's poor efficiency. Don't get me wrong, I was clueless and miserable the first week in but once I understood the very fundamentals, branching out to evolve the fundamental requirements became very rewarding. Your teacher is not giving you the best tools because that is one of the things that completely kill creativity and understanding. Why bother error checking with switch or if statements when you can simply use try-catch blocks? Why should you parse through a list component variable by variable instead of using a function which does it for you? The answer you're looking for won't always be the easiest of ways, but it will only get easier when you understand when and why to use the tools given to you.

share|improve this answer

One skill you need to learn in order to survive school, work, and even in life, is to learn to pick your battles. In this case, unless the people giving the course are either breaking the law, or otherwise behaving in an unethical manner, then there usually isn't much you can do about these things. It isn't even a case of whether you are right or not. You need to learn when to question, then when to either question further, or to simply go with the flow.

University is really a means to an end. It's a few years of learning how to cope with stress and how to educate yourself. In IT, you are rarely being taught much in your lectures that will last you more than a few years, and by the time you leave school, the only real skills you will have will be to deal with stress, meet deadlines, and most importantly about how to further your education on your own while you work.

While I realize this doesn't specifically satisfy your question, my advice is to simply play along. By the end of it all, you will either have learned to accept what you have been taught, or you will have learned to learn from multiple sources and to make up your own mind in the end. Either way, you'll save yourself a lot of stress if you simply get the work done, and then move beyond it. This in itself is a very useful social skill to learn when you find yourself with a potentially disagreeable boss and a job that isn't being dove the way you would do it yourself.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.