Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I explain loose coupling and information hiding to a new programmer? [closed]

Tags:

oop

How do I explain loose coupling and information hiding to a new programmer? I have a programmer who I write designs for, but who can't seem to grasp the concepts of loose coupling and information hiding.

I write designs with everything nicely broken down into classes by function (data access is separate, a class for requests, a controller, about 5 classes total). They come back with a modified design where half the classes inherit from the other half (and there is no "is-a" relationship), and many public variables.

How can I get across the idea that keeping things separate makes it easier to maintain?

like image 498
C. Ross Avatar asked Feb 27 '09 13:02

C. Ross


3 Answers

Ask him if it's a good idea to let you borrow $10 by giving his wallet to you for a moment and taking the money yourself.

like image 122
Boris Pavlović Avatar answered Oct 15 '22 14:10

Boris Pavlović


The problem is your expectations, not the developers lack of skill. You talk about loose coupling and information hiding as if these are simple facts or mechanical techniques - they are not. Software development is a craft and the only way to get better at a craft is to practice it and slowly and incrementally improve.

You are looking for a shortcut. You want the developer to experience an "ahah!" moment and suddenly see the wisdom in your design. I say, don't hold your breath.

Adopt the mindset of a mentor. If you want him to improve his design skills, don't "hand" him a design, let him to design it! Then review the design with him. This will give him experience, a deeper sense of ownership and more willingness to listen to your suggestions before he is knee deep in implementation.

An aside - I notice that people look for these shortcuts all the time with abstract skills but not with more "physical" skills. Take tennis for example. If you were a tennis coach and a new player kept hitting his forehands long, you wouldn't just show him a YouTube video of a Roger Federer forehand and expect him to "get it". A great forehand takes YEARS of experience as you learn the feeling and use it in different scenarios - its not your muscles learning, its your brain. It is no different with software design. You get good at it by doing it over and over again. You slowly learn from your mistakes and get better at appreciating the consequences of each individual design decision.

like image 17
Maurice Flanagan Avatar answered Oct 15 '22 15:10

Maurice Flanagan


The best way to explain these kinds of concepts is to use analogies. Pick something non-programming related and use that to explain the abstract design concepts.

The following image is pretty good at explaining the need for loose coupling:

Dependency Inversion Principle: Would You Solder A Lamp Directly To The Electrical Wiring In A Wall?

Try to come up with stuff like this that will amuse and pertain to your new programmer.

like image 12
Andrew Hare Avatar answered Oct 15 '22 14:10

Andrew Hare