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.
class Araba
{
public string Marka;
public int Yil;
}
Ş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.
Araba araba1 = new Araba();
araba1.Marka = "Toyota";
araba1.Yil = 2022;
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.
Araba araba1 = new Araba();
araba1.Marka = "BMW";
Araba araba2 = new Araba();
araba2.Marka = "Mercedes";
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.
class Araba
{
public string Marka;
public void Calistir()
{
Console.WriteLine("Araba çalıştı.");
}
}
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.