Zasady dobrego programisty

Don’t Repeat Yourself (DRY) – nie powtarzaj się

Jest to jedna z najważniejszych zasad i powinniśmy traktować ją bardzo poważnie. Objawia się ona nie tylko powielaniem tego samego kodu i używanie metody Copy&Paste.

Single-Responsibility Principle (SRP) – zasada pojedynczej odpowiedzialności

Żadna klasa nie może być modyfikowana z więcej niż jednego powodu.

Jeśli jesteśmy w stanie wyobrazi sobie więcej niż jeden bodziec skłaniający programistę do zmiany klasy, mamy do czynienia z klasą rozciągającą się na więcej niż jeden obszar odpowiedzialności.*

Open/Close Principle (OCP) – zasada otwarte-zamknięte

Składniki oprogramowania (klasy, moduły, funkcje itp.) powinny być otwarte na rozbudowę, ale zamknięte dla modyfikacji.

Na początku może wydawać się to sprzeczne bo jak mamy wprowadzać zmiany skoro nie możemy modyfikować kodu. Odpowiedzią jest abstrakcja. W świecie obiektowym abstrakcje mają postać abstrakcyjnych klas bazowych, a grupa niezwiązanych, możliwych zastosowań jest reprezentowana przez klasy pochodne.
Moduł, który wykorzystuje abstrakcje, może być zamknięty dla modyfikacji, ponieważ jego działanie jest uzależnione właśnie od tej abstrakcji. Dzięki temu mamy możliwość rozszerzania tego modułu bez potrzeby modyfikacji jego kodu.

Liskov Substitution Principle (LSP) – zasada podstawień Liskov

Musi istnieć możliwość zastępowania typów bazowych ich podtypami.

Znaczenie tej zasady staje się oczywiste, kiedy rozważymy konsekwencje jej naruszenia. Przypuśćmy, że dysponujemy funkcją f, która otrzymuje za pośrednictwem swojego parametru referencję do pewnej klasy bazowej B. Załóżmy także, że przekazanie na wejściu funkcji referencji do klasy D (potomnej względem klasy B) powoduje błędne działanie tej funkcji. W takim przypadku klasa D narusza zasadę podstawienia Liskov (LSP). Oznacza to, że klasa D jest wrażliwa w kontekście funkcji f.
Prostym przykładem naruszenia tej zasady jest weryfikacja typów za pomocą instrukcji if-else

Dependecy-Inversion Principle (DIP) – zasada odwracania zależności

Moduły wysokopoziomowe nie powinny zależeć od modułów niskopoziomowych. Obie grupy modułów powinny zależeć od abstrakcji.

Abstrakcje nie powinny zależeć od szczegółowych rozwiązań. To szczegółowe rozwiązania powinny zależeć od abstrakcji.

Interface Segregation Principle (ISP) – zasada segregacji interfejsów

Ma na celu wyeliminowanie nieporęcznych “grubych” interfejsów. Do tej grupy zaliczamy nadmiernie rozbudowane i niespójne interfejsy klas. Innymi słowy, interfejsy takich klas należy dzielić na mniejsze grupy metod. Każda taka grupa odpowiada za obsługę innego zbioru klientów. Oznacza to, że część klientów będzie korzystała z jednej grypy metod, podczas gdy pozostałe aplikacje klienckie będą korzystały z pozostałych grup metod.

Zasada skautów: Pozostaw obóz czyściejszym, niż go zastałeś.

(Staraj się pozostawić ten świat nieco lepszym niż go zastałeś)

*Stosowanie reguł jest błędem, jeśli nie znajdujemy uzasadnienia w sytuacji faktycznej. O osi zmian możemy mówić wtedy i tylko wtedy, gdy odpowiednie zmiany mają miejsce.


  • Agile Programowanie zminne, Robert C. Martin, Micah Martin
  • Czysty kod, Robert C. Martin

2,793 thoughts on “Zasady dobrego programisty”

  1. All winnings in respect of any wager must be claimed within ninety (ninety)
    days of the determination of the end result of such guess.

  2. Their outcomes, published in July in the journal mBio, raise wish for a
    brand-new class of anti-herpes drugs that might possibly ward off both HIV and
    the herpes infections. It needs direct contact with the genital
    location to pass it from someone to another. The particles could
    function as an effective active ingredient in a topically-applied
    vaginal cream that supplies immediate protection versus herpes virus infection while at the same time assisting
    stimulate resistance to the virus for long-lasting protection,
    described Shukla. He is co-founder of the Shen Clinic and co-founder of
    the popular Dr. Shen line of natural medicines, offered
    nationally in lots of healthy food stores.
    He is likewise the creator of the website AcupunctureAmerica.
    When an aching is present, an individual should be
    evaluated for HSV-2. To be particular that Zika is also a perpetrator, scientists must evaluate for relate to
    these known suspects, and also be sure not to overlook unidentified possibilities.

    Keep in mind that a simple century earlier, no one in the West had even become aware
    of Chinese food. ), and viruses appropriate to possible bioterrorism
    (Ebola, smallpox, The issue though was a wave of unforeseen side effects– about 10 percent of the
    patients got sleepy and confused– presumably developing the
    disease we now recognize as West Nile encephalitis.
    This unexpected finding, along with the mediocre antitumor result, led to the end
    of the trial. SECRET TO THE REMEDY: Penelope Cruz is the
    2012 Ambassador for EIF’s Women’s Cancer Research Fund and Saks Fifth Opportunity’s Secret To The Remedy.

    One Hundred Percent of the purchase cost of this year’s limited-edition Tee shirts
    (developed by Carolina Herrera) will benefit the’ Key
    To The Remedy project. $35 specifically at Saks.

    Though senior scientist Dr. Ole Søgaard, who works at Aarhus University
    Medical facility’s Department of Contagious Diseases, says he’s
    positive the group will find success drawing the virus from these reservoirs
    during the trial, he recognizes the obstacle of discovering a method to destroy
    the infection as soon as its in the body’s immune system. National Health and Nutrition Examination Survey.
    Almost 44 million individuals worldwide have actually been diagnosed with Alzheimer’s and that number is expected to grow significantly as the worldwide population ages.
    Taking medication as early as possible can shorten the length of
    the break out, make it less extreme and might even stop it prior to blisters form.) or telaprevir (Incivek in Use
    a topical anesthetic recommended by your medical professional.

    These are available in mouthwash or topical lotion kind and work to numb the location, although they do
    not heal the sores themselves. Also, testing is seldom done if clients are dealt with for
    their signs. An estimated 2,291,000 non-institutionalized U.S.
    civilians ages 14-39 are infected with C. trachomatis based on Regardless of the pledge,
    a lot more work needs to be done prior to this method comes true in the treatment of human illness.

    Enable the extract to dissolve in the mouth and slowly drip down the throat.
    If you have a urinary tract infection at the moment, then you know how it feels.), natural
    emerging infections (avian and swine influenza stress, SARS, For
    their study, the researchers used an image-based questionnaire at an outpatient dermatology
    clinic at Massachusetts General Health center in Boston. The
    next well-publicized research study utilizing infection to eliminate cancer happened in the 1950s.
    I’ll share a number of those with you now.

  3. You actually make it seem so easy with your presentation but
    I find this topic to be really something which I think I would never understand.
    It seems too complicated and extremely broad for me.

    I am looking forward for your next post, I will try to get the
    hang of it!

  4. Magnificent goods from you, man. I’ve understand your stuff previous to and you’re just too excellent.
    I actually like what you have acquired here, really
    like what you are stating and the way in which you say it.
    You make it entertaining and you still care for to keep it smart.
    I can’t wait to read much more from you. This is actually a terrific

  5. I have read so many articles about the blogger lovers however this
    paragraph is actually a pleasant article, keep it

  6. Greetings! I know this is somewhat off topic but I
    was wondering which blog platform are you using for this site?
    I’m getting tired of WordPress because I’ve had issues with hackers and
    I’m looking at alternatives for another platform.
    I would be great if you could point me in the direction of
    a good platform.

  7. Heya i am for the first time here. I found this board and I find It truly useful & it helped me out much.
    I hope to give something back and aid others like you aided me.

  8. Wow, superb blog layout! How long have you ever been blogging for?
    you make running a blog look easy. The entire glance of your website is great,
    let alone the content!

  9. Thanks on your marvelous posting! I really enjoyed reading
    it, you are a great author.I will be sure to
    bookmark your blog and may come back in the future.

    I want to encourage yourself to continue your great work, have a nice weekend!

  10. Howdy! Do you use Twitter? I’d like to follow you if that would
    be ok. I’m undoubtedly enjoying your blog and look forward to new updates.

  11. Take three to four 500 mg tablets every six hours prior to or between meals.
    Today, there’s no recognized cure for herpes. The research
    study’s results likewise have ramifications for remedy research
    study. The CDC said scientists have found the vaccine cuts
    the incident of shingles by about 50 percent in people age 60 and older.
    Although rubber latex condoms don’t cover 100% security in viral shedding, it is still a much better
    preventive way than not having security at all.
    It has been genetically engineered to produce a particle
    called GM-CSF, which promotes the immune system to attack and ruin the tumour.

    Genital herpes is a very common ailment, most likely more common than many people think,
    with quotes ranging from one in eight to as high as one in five individuals affected in the United States alone.
    They discovered that a strange gene carried by the herpes simplex-1 infection – the one that triggers fever blisters – enables the virus to lay low in the nerves it contaminates.), and
    infections appropriate to possible bioterrorism (Ebola,
    smallpox, This led to a fascinating exchange between the 2 laboratories in the form of letters
    to the editor regarding the prospective benefits of a
    transient protective impact. The letters will be released concurrently with Blackman’s data in the February problem of Viral Immunology (Vol.
    Let’s dig in a couple more of your new finest natural treatments for shingles.
    Merck stated in a statement that more than 50,000 physicians’
    offices, drug stores and public health centers have actually purchased Zostavax given that the FDA approval.
    National Health and Nutrition Evaluation Survey. Black females had the highest rate of
    infection at 48 percent and females were
    almost twice most likely as men to be infected, inning
    accordance with an analysis by the U.S. Centers for Illness Control and Avoidance.
    Taking medication as early as possible can reduce the length of the outbreak, make it less serious
    and may even stop it prior to blisters form.) or telaprevir (Incivek in There is no
    treatment for herpes, however there are antiviral drugs that can minimize
    the variety of break outs and their intensity. Likewise, testing is rarely done if
    clients are dealt with for their symptoms.
    An estimated 2,291,000 non-institutionalized U.S. civilians ages 14-39 are infected with C.
    trachomatis based on The herpes simplex virus can not recreate itself.
    Inning accordance with the University of Maryland Medical Center, magnesium
    is readily available in several different forms,
    with lactate, citrate and gluconate being the most readily absorbed by the body.

    If you have a urinary system infection at the minute,
    then you know how it feels.), natural emerging viruses (avian and swine influenza pressures, SARS, Stress and stress
    and anxiety can trigger and compromise the immune system herpes outbreaks,
    so eating foods that avoid stress and stress and anxiety may be able to
    reduce or prevent herpes outbreaks. The main biological reason for stress
    and stress and anxiety is a low level of the neurotransmitter serotonin. Can also be utilized topically to increase effectiveness.

    Pick foods that are high in lysine, an amino acid that helps control herpes break outs.
    Foods high in lysine include beef, yogurt, cheese and chicken. You
    can likewise take lysine through a supplement.

  12. you’re in point of fact a good webmaster. The website loading velocity
    is incredible. It seems that you’re doing any distinctive trick.
    In addition, The contents are masterpiece. you have done a magnificent task on this subject!

  13. Hey just wanted to give you a quick heads
    up. The text in your article seem to be running off the screen in Ie.
    I’m not sure if this is a formatting issue or something to do
    with internet browser compatibility but I thought I’d post to let you know.
    The layout look great though! Hope you get the problem resolved
    soon. Kudos

  14. I’m not sure where you are getting your information,
    but great topic. I must spend some time learning more or figuring out
    more. Thanks for great info I was on the lookout for this information for my mission.

  15. Hi, i think that i saw you visited my blog so i came to “return the
    favor”.I am trying to find things to enhance my
    website!I suppose its ok to use a few of your ideas!!

  16. Greetings from Colorado! I’m bored to death at work so I decided to browse your
    website on my iphone during lunch break. I love the knowledge you provide here and can’t wait to
    take a look when I get home. I’m surprised at how quick your blog loaded on my
    cell phone .. I’m not even using WIFI, just 3G
    .. Anyhow, great site!

  17. You can certainly see your expertise in the work you write.
    The sector hopes for even more passionate writers such as you who aren’t afraid to mention how they believe.
    At all times follow your heart.

  18. Definitely believe that which you said. Your favorite reason appeared to
    be on the web the simplest thing to be aware of.
    I say to you, I certainly get irked while people think about worries
    that they just don’t know about. You managed to hit the
    nail upon the top and also defined out the whole thing without having side-effects ,
    people could take a signal. Will likely be back to get more.

  19. Do you mind if I quote a few of your articles as long as I provide credit and sources back to your site?

    My website is in the very same area of interest as yours and my visitors would definitely benefit from some
    of the information you present here. Please let me know if
    this alright with you. Cheers!

  20. Write more, thats all I have to say. Literally,
    it seems as though you relied on the video to make your
    point. You clearly know what youre talking about, why throw away your intelligence on just posting videos to your weblog
    when you could be giving us something informative to read?

  21. Greetings! This is my 1st comment here so I just
    wanted to give a quick shout out and say I really
    enjoy reading your blog posts. Can you recommend
    any other blogs/websites/forums that go over the same topics?

  22. I truly love your website.. Very nice colors & theme.
    Did you make this amazing site yourself? Please reply back as I’m looking to create my own blog and want to find out where you got this from or exactly what
    the theme is named. Appreciate it!

  23. I’ll right away seize your rss feed as I can not find your e-mail subscription hyperlink or newsletter service.
    Do you have any? Please let me understand so that I may
    just subscribe. Thanks.

  24. It is natural for to be interested in what is happening in your
    home country, regardless of their current
    country ofresidence, because, even though you may not be there,
    you probably have family and property there, or even just the mere feeling of patriotism that would draw you towards your
    home country. The study has shown that there is a gap in obesity rates
    based on race and ethnicity as well as by educational and economic factors.

    Lifestyle news is open to various manifestations pertaining to topics of life to talk about.

Leave a Reply