Ana Sayfa Hakkımda Dersler Blog MikrofondaOn The Mic İletişim Projeler Yakında
DerslerLessons TEMEL · C#

C# Temelleri — Class ve Object C# Basics — Class and Object

9 dk okuma 9 min read · Emre Ulutabak
1
Class nedir? What is a class?

Bir araba üretmek istediğini düşün. Önce tasarım gerekir: kaç kapılı olacak, rengi ne olacak, motor tipi ne olacak. Bu tasarımın kendisi henüz gerçek araba değildir.

Yazılımda buna benzer yapı class'tır. Class, bir nesnenin planı ya da şablonudur.

Imagine you want to build a car. First you need a design: how many doors, what color, what engine type. That design itself is not yet a real car.

In software, the similar concept is a class. A class is the blueprint or template of an object.

csharp
class Araba
{
    public string Marka;
    public int Yil;
}
💡
Class, gerçek nesneyi değil, onun nasıl görüneceğini tarif eder. A class does not represent the real object itself, but describes how it should look.
2
Object nedir? What is an object?

Şablondan gerçek bir örnek ürettiğinde artık elinde bir nesne vardır. İşte bu nesneye object denir.

Yani class plan ise, object o planın hayata geçmiş halidir.

When you create a real example from the blueprint, you now have an actual object. That is called an object.

So if the class is the plan, the object is the realized version of that plan.

csharp
Araba araba1 = new Araba();
araba1.Marka = "Toyota";
araba1.Yil = 2022;
💡
new anahtar kelimesiyle class'tan gerçek bir nesne üretirsin. With the new keyword, you create a real object from a class.
3
Örnek mantığı Instantiation logic

Aynı class'tan birden fazla object üretilebilir. Aynı model telefondan farklı renklerde ve sahiplerde birçok cihaz olması gibi düşünebilirsin.

Hepsi aynı şablondan gelir ama her nesnenin değeri farklı olabilir.

You can create multiple objects from the same class. Think of many phones of the same model, each with different colors and owners.

They all come from the same blueprint, but each object can hold different values.

csharp
Araba araba1 = new Araba();
araba1.Marka = "BMW";

Araba araba2 = new Araba();
araba2.Marka = "Mercedes";
💡
Aynı class, farklı veriler taşıyan birçok object üretebilir. The same class can create many objects carrying different data.
4
Property ve metot Property and method

Bir class içinde veriler olabilir, bunlar property ya da alan gibi düşünülür. Aynı zamanda davranışlar da olabilir; bunlara metot denir.

Yani nesne hem bilgi taşır hem de iş yapabilir.

A class can contain data, which you can think of as properties or fields. It can also contain behaviors, which are called methods.

So an object can both store information and perform actions.

csharp
class Araba
{
    public string Marka;

    public void Calistir()
    {
        Console.WriteLine("Araba çalıştı.");
    }
}
💡
Property nesnenin bilgisini, metot ise davranışını temsil eder. A property represents the object's data, while a method represents its behavior.
5
Altın kurallar Golden rules

Class ve object konusu nesne yönelimli programlamanın temelidir. Başta soyut gelebilir ama örneklerle çok hızlı oturur.

Classes and objects are the foundation of object-oriented programming. They may feel abstract at first, but examples make them click quickly.

💡
Class'ı kalıp, object'i o kalıptan çıkan gerçek ürün gibi düşün. Think of the class as the mold, and the object as the real product made from that mold.
💡
Bir class çok şey yapıyorsa sadeleştirmeyi düşün. If a class is doing too many things, consider simplifying it.
💡
İsimlendirme çok önemlidir. Class isimleri genelde isim olur: Araba, Musteri, Siparis gibi. Naming matters a lot. Class names are usually nouns: Car, Customer, Order, and so on.
MİNİ QUIZ MINI QUIZ
Aşağıdakilerden hangisi doğrudur? Which of the following is correct?
Object, class'ın planıdır An object is the blueprint of a class
Class, object üretmek için kullanılan şablondur A class is the template used to create objects
new anahtar kelimesi class'ı siler The new keyword deletes a class
Bir class'tan sadece bir object üretilebilir Only one object can be created from a class