Ana sayfa Genel Python – Kalıtım (Inheritance)

Python – Kalıtım (Inheritance)


Python – Kalıtım (Inheritance)

Bu konuda Nesne Yönelimli Programlamadaki inheritance(kalıtım veya miras alma) konseptini öğrenmeye çalışacağız. Inheritance veya kalıtım bir sınıfın başka bir sınıftan özelliklerini(attribute ) ve metodlarını miras almasıdır.

Bu konsepti aslında bizim kendi anne babamızdan değişik özellikleri ve davranışları miras almamıza benzetebiliriz.(Hani derler ya ! Babasına çekmiş 🙂 )

Peki inheritance nerede işimize yarar ? Örneğin, bir şirketin çalışanlarını tasarlamak için sınıflar oluşturuyoruz. Bunun için Yönetici, Proje Direktörü, İşçi gibi sınıflar oluşturmamız gerekiyor. Aslında baktığımız zaman bu sınıfların hepsinin belli ortak metodları ve özellikleri bulunuyor. O zaman bu ortak özellikleri ve metodları tekrar tekrar bu sınıfların içinde tanımlamak yerine, bir tane ana class tanımlayıp bu classların bu classın özelliklerini ve metodlarını almalarını sağlayabiliriz. Inheritance’ın veya Kalıtım’ın temel mantığı budur.

İsterseniz inheritance yapısını kurmak için öncelikle bir tane çalışan sınıfı oluşturalım.

Çalışan sınıfını oluşturduk şimdi de Yönetici sınıfını bu Çalışan sınıfından türetmeye çalışalım.

Burada, yönetici sınıfında herhangi bir şey tanımlamadık ancak Çalışan sınıfından bütün özellikleri ve metodları miras aldık. Bakalım burada Çalışan sınıfının metodlarını kullanabilecek miyiz ?

Burada gördüğümüz gibi bütün özellikleri ve metodları Çalışan sınıfından miras aldığımız için kullanabiliyoruz. Bunu dir() fonksiyonu ile de görebiliriz.

Peki biz Yönetici sınıfına ekstra fonksiyonlar ve özellikler ekleyebiliyor muyuz ? Örnek olması açısından zam_yap isimli bir metod ekleyelim.

İşte biz bir sınıftan miras alarak oluşturduğumuz sınıflara ekstra metodlar ve özellikler de ekleyebiliyoruz.

Overriding (İptal Etme)

Eğer biz miras aldığımız metodları aynı isimle kendi sınıfımızda tekrar tanımlarsak , artık metodu çağırdığımız zaman miras aldığımız değil kendi metodumuz çalışacaktır. Buna Nesne Tabanlı Programlamada bir metodu override etmek denmektedir.

Örneğin artık Çalışan sınıfının init metodunu kullanmak yerine Yönetici sınıfında init metodunu override edebiliriz. Böylelikle Yönetici sınıfına ekstra özellikler(attribute) ekleyebiliriz.

İsterseniz şimdi de bilgilerigoster metodunu override edelim.

super Anahtar Kelimesi

super anahtar kelimesi özellikle override ettiğimiz bir metodun içinde aynı zamanda miras aldığımız bir metodu kullanmak istersek kullanılabilir. Yani super en genel anlamıyla miras aldığımız sınıfın metodlarını alt sınıflardan kullanmamızı sağlar. Hemen örnek üzerinden anlamaya çalışalım.

Burada super().__init() diyerek Çalışan sınıfının metodunu özel olarak çağırarak isim, maaş , departman özelliklerini bu metodla belirledik.

İşte inheritance konusu bu kadar ! İlk başlarda karışık gelmiş gibi görünebilir. Ancak bu yapıları kullana kullana alışacaksınız.


  1. Terrific article! This is the type of info that are meant to be shared around the net.
    Shame on the search engines for now not positioning this post higher!
    Come on over and talk over with my web site . Thanks =)

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

  3. I was very pleased to find this web-site.I wanted to thanks for your time for this wonderful read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you blog post.

  4. Very nice article and straight to the point. I don’t know if this is actually the best place to ask but do you guys have any thoughts on where to get some professional writers? Thank you 🙂

  5. Greetings from Idaho! I’m bored to tears at work so I decided
    to check out your blog on my iphone during lunch break.
    I love the information you present here and can’t wait to take a look when I get home.
    I’m surprised at how fast your blog loaded on my mobile .. I’m not even using WIFI, just 3G ..
    Anyways, fantastic site!

  6. I have not checked in here for a while since I thought it was getting boring, but the last few posts are good quality so I guess I’ll add you back to my everyday bloglist. You deserve it my friend 🙂

  7. Hi, i think that i saw you visited my weblog thus i came to “return the want”.I am trying to in finding things to enhance my web site!I guess its ok to use some of your ideas!!

  8. Hi there, i read your blog from time to time and i own a similar one and i was just wondering if you get a lot of spam responses? If so how do you protect against it, any plugin or anything you can recommend? I get so much lately it’s driving me mad so any help is very much appreciated.

  9. I think this is among the most vital info for me. And i am glad reading your article. But wanna remark on few general things, The website style is great, the articles is really great : D. Good job, cheers

  10. An impressive share! I’ve just forwarded this onto a friend who had been doing
    a little homework on this. And he in fact bought me breakfast due to the
    fact that I found it for him… lol. So let me reword this….
    Thanks for the meal!! But yeah, thanks for spending the time to discuss
    this topic here on your site.

  11. Admiring the persistence you put into your website and detailed information you present. It’s good to come across a blog every once in a while that isn’t the same out of date rehashed information. Great read! I’ve bookmarked your site and I’m including your RSS feeds to my Google account.

  12. Hello! I’ve been following your weblog for a long time now and
    finally got the courage to go ahead and give you a shout out from Austin Tx!
    Just wanted to mention keep up the excellent job!

  13. Thank you a lot for sharing this with all people you really know what you’re speaking approximately! Bookmarked. Please additionally consult with my site =). We may have a link change arrangement between us!

  14. I would like to thank you for the efforts you have put in writing this blog. I’m hoping the same high-grade blog post from you in the upcoming also. Actually your creative writing skills has encouraged me to get my own blog now. Really the blogging is spreading its wings fast. Your write up is a good example of it.

  15. I have not checked in here for some time since I thought it was getting boring, but the last few posts are good quality so I guess I?¦ll add you back to my everyday bloglist. You deserve it my friend 🙂

  16. Your style is so unique compared to many other people. Thank you for publishing when you have the opportunity,Guess I will just make this bookmarked.2

  17. Hello, Neat post. There’s a problem together with your website in internet explorer, could test thisK IE still is the marketplace chief and a big component to other folks will omit your fantastic writing because of this problem.

  18. You really make it seem so easy with your presentation but I find this topic to be actually something that I think I would never understand. It seems too complicated and extremely broad for me. I’m looking forward for your next post, I will try to get the hang of it!

  19. certainly like your web site however you have to test the spelling on quite a few of your posts. Several of them are rife with spelling problems and I in finding it very troublesome to inform the reality however I’ll surely come back again.

  20. 高能聚焦量超聲波( HIFU )以物理性聚焦集中成一點, 快速穿透皮膚真皮及脂肪層面直達面部表淺肌肉腱膜系統( SMAS )層令其組織細胞分子高速磨擦 , 瞬間升溫至60 -70 度,令整個表淺肌肉腱膜系統( SMAS )受熱收縮,形成熱固化區域, 令結綈組織同時拉緊,達到拉皮防皺及美容效果。SMAZ聚焦超聲波提供了最有效的HIFU能量收緊皮膚及刺激胶原蛋白新生,提升彈性,恢復更緊緻的皮膚和更年輕的美貌。

  21. Do you mind if I quote a few of your posts as long as I provide credit and sources back to your webpage? My website is in the exact same niche as yours and my users would certainly benefit from a lot of the information you present here. Please let me know if this okay with you. Thanks!

  22. I would like to show appreciation to this writer for rescuing me from this type of crisis. Because of searching through the search engines and coming across strategies which are not beneficial, I thought my life was well over. Being alive devoid of the answers to the issues you have solved by way of your report is a crucial case, as well as the kind which may have badly damaged my career if I had not noticed your blog. Your main talents and kindness in handling all the pieces was tremendous. I don’t know what I would’ve done if I had not come upon such a point like this. I can also now look ahead to my future. Thanks a lot so much for this high quality and result oriented help. I won’t hesitate to propose your web page to any individual who would need counselling on this topic.

  23. Can I just say what a relief to find someone who actually knows what theyre talking about on the internet. You definitely know how to bring an issue to light and make it important. More people need to read this and understand this side of the story. I cant believe youre not more popular because you definitely have the gift.

  24. I used to be recommended this website by means of my cousin. I am now not certain whether this publish is written by way of him as nobody else know such special about my difficulty. You are incredible! Thank you!

  25. I’m impressed, I need to say. Really rarely do I encounter a blog that’s both educative and entertaining, and let me inform you, you might have hit the nail on the head. Your idea is excellent; the difficulty is something that not enough individuals are speaking intelligently about. I’m very completely satisfied that I stumbled across this in my seek for one thing referring to this.

  26. Great beat ! I wish to apprentice even as you amend your website, how can i subscribe for a blog web site? The account aided me a appropriate deal. I have been a little bit familiar of this your broadcast offered shiny clear idea

  27. This blog is definitely rather handy since I’m at the moment creating an internet floral website – although I am only starting out therefore it’s really fairly small, nothing like this site. Can link to a few of the posts here as they are quite. Thanks much. Zoey Olsen

  28. You actually make it appear so easy together with your presentation however I to find this matter to be really one thing which I believe I would by no means understand. It sort of feels too complicated and very broad for me. I am looking forward on your next put up, I will try to get the grasp of it!

  29. of course like your website but you have to check the spelling on quite a few of your posts. A number of them are rife with spelling problems and I find it very bothersome to tell the truth nevertheless I’ll surely come back again.

  30. Excellent blog! Do you have any tips for aspiring writers? I’m hoping to start my own website soon but I’m a little lost on everything. Would you suggest starting with a free platform like WordPress or go for a paid option? There are so many options out there that I’m completely overwhelmed .. Any tips? Kudos!


Lütfen yorumunuzu giriniz
Buraya isminizi giriniz