Class'larClasses

This page is part of an incremental translation project. Body text not yet translated to Turkish falls back to English even in TR mode.

Object oriented programming'de, class; bazı feature'lara (member'lara), davranışa (method'lara) ve bir initial state'e sahip genişletilebilir bir yapıdır. Object oriented bir programlama dili olarak, TROIA da class'ları destekler. Bu bölüm, TROIA'da konsepti ve key feature'larını tanıtmayı amaçlar.In object oriented programming, a class is an extensible structure that has some features (members), behavior (methods) and an initial state. As an object oriented programming language, TROIA also supports classes. This section aims to introduce concept an its key features in TROIA.

GirişIntroduction

Kısacası, TROIA class'ları; method olarak davranışlara, member olarak feature'lara ve initial state'leri ayarlamak için constructor'lara sahip yazılım yapılarıdır. Bu feature'larla TROIA class'ları, en çok kullanılan object oriented dillerin (java, c# vb.) class'larına çok benzer. Programlama pratiklerine gelince, TROIA class'larının diğer object oriented dillerden bazı farklı yönleri vardır.Briefly, TROIA classes are software structures that have behaviors as methods, features as members, and constructors to set initial states. With these features TROIA classes are very similar to most used object oriented language’s classes (such as java, c# etc). When it comes to programming practices, TROIA classes have some different aspects from other object oriented languages.

Object oriented dillerde, genellikle tüm yapılar (user interface form'ları, form element'leri gibi) de framework'ün kendisine dahil edilen class'lardır ve programcılar bu class'ları extend edebilir ve/veya yeni class'lar implement edebilir. TROIA'da, dialog'lar, report'lar ve diğer ui item'ları class olarak kabul edilmez. TROIA class'ları, dialog'lar veya report'larla aynı seviyeli yapılardır. Başka bir deyişle, dialog'lar class değildir.In object oriented languages, usually all structures (such as user interface forms, form elements) are also classes which are included in framework’s itself and programmers able to extend this classes and/or implement new classes. In TROIA, dialogs, reports and other iu items are not considered as class. TROIA classes are same level structures with dialogs or reports. In other words, dialogs are not classes.

Ayrıca, TROIA class'ları feature'ları temsil etmek için member field'ları saklayabilse de, bazı davranışlar ekleyen "method setleri" olarak kabul edilirler. Çünkü TROIA'nın object'in feature'larını saklamak için class'lara "alternatif bir yapısı" vardır. Bu "alternatif yapının" "table" olduğu açıktır, ilerleyen bölümlerde ele alınacaktır. Ama gerçek hayattaki object'leri temsil etmek için class member'larını kullanmanın teknik bir kısıtlama olmadığını, bunun sadece programlama pratikleriyle ilgili olduğunu vurgulamalıyız.Additionally, even if TROIA classes are able to store member fields to represent features, they are considered as “sets of methods” that adds some behavior. Because TROIA has an “alternative structure” to classes for storing object’s features. It is obvious that this “alternative structure” is “table” which will be discussed next sections. But we must emphasize that there is not a technical constraint to use class members to represend real-life objects, its just about programming practices.

Class Oluşturma/DüzenlemeCreating/Editing Classes

Class'lar, TROIA IDE'de ve "DEVT00 - Class-Browser" transaction'ında tanımlanır ve düzenlenir. DEVT00, TROIA class'larını yönetmek için daha eski bir seçenektir ama class'lar için SQL script'leri oluşturma gibi bazı ekstra feature'lara sahiptir. Class'ları yönetmek için TROIA IDE'ye odaklanacağız.Classes are defined and edit classes in TROIA IDE and “DEVT00 - Class-Browser” transaction. DEVT00 is an older option to manage TROIA classes but has some extra features such as creating SQL scripts for classes etc. We will focus on TROIA IDE to manage classes.

Yeni bir class oluşturmak için, menüde TROIA IDE->New->Class'a tıklamalı ve new class form'unu doldurmalısınız.To create a new class you must click TROIA IDE->New->Class on menu and fill the new class form.

TROIA screenshot

Görüldüğü gibi, class'ınızın benzersiz bir ismi olmalıdır. Yeni class'ınız için bir base class tanımlamak zorunlu değildir, bu yüzden yeni class'ınızın bir base'i yoksa base class field'ını boş bırakabilirsiniz. "Short description", class'ınız hakkında basit bir dokümantasyon text'idir. "Module" ve "Status" sadece dokümantasyon konuları içindir ve class kullanımı üzerinde kritik bir etkisi yoktur. New class form'unda "OK" butonuna tıkladıktan sonra, IDE iki boş basic method içeren yeni bir class oluşturur ve yeni class'ınızı object explorer'da açar.As it is obvious that, your class must have a unique name. It is not a compulsory define a base class for your new class, so you can leave base class field if your new class has not a base. “Short description” is a simple documentation text about your class. “Module” and “Status” are just for documentation issues and have no critical effect on class usage. After you click “OK” button on new class form, IDE creates a new class which contains two emtpty basic methods and opens your new class on object explorer.

Mevcut class'larınızı düzenlemek için, menüde TROIA IDE->Open Resource'a tıklamalı ve class'larınızı bulup açmalısınız. Hem class tanımlamanın hem düzenlemenin bir change request olan bir hotline gerektirdiği açıktır.To edit your existing classes you must click TROIA IDE->Open Resource on menu and find and open your classes. It is obvious that both for defining and editing classes requires an hotline which is a change request.

Class'lar Nasıl Saklanır?How Classes Stored?

Bir class'ı tanımlayan iki tür bilgi vardır. İşte tüm class'ların development bilgisini saklayan table'lar.There are two types of information that defines a class. Here is the tables that stores all development information classes.

SYSCLSHEADStores basic information of class such as class name, base class
SYSCLSFUNCStores class methods information such as codes, return type

Bir class'ı convert ettiğinizde, TROIA interpreter bu iki table'ı okur, kodu compile eder ve .cls uzantılı binary class dosyalarını kullanıcının class path'ine kaydeder. Class instance'ları oluşturulduğunda yalnızca bu dosyalar okunur, başka bir deyişle bir class tanımlandığında sistem class bilgisini ve kodlarını saklayan database table'larına erişmez.When you convert a class, TROIA interpreter reads these two tables, compiles the code and saves binary class files with .cls extension to user’s class path. Only these files are read when class instances created, in other words when a class defined system does not access database tables that stores class information and codes.

Basic Class Method'larıBasic Class Methods

Class'ların _VARIABLES, _CONSTRUCTOR adlı iki önceden tanımlı method'u vardır; bu method'lar bir variable definition komutu yeni bir class instance'ı tanımladığında çağrılır. Bunlara "class initializer" method'ları da denir ve çoğunlukla diğer object oriented programlama dillerindeki constructor'lara benzer.Classes has two predefined methods named _VARIABLES, _CONSTRUCTOR, this methods are called when an variable definition command defines a new class instance. They are also called “class initializer” methods and mostly like constructors on other object oriented programming languages.

Bir programming convention olarak _VARIABLES method'u member'ları ve diğer gerekli variable'ları tanımlamak için, _CONSTRUCTOR method'u class instance'ının internal yapılarını oluşturmak için kullanılır. Ama bunları farklı amaçlar için kullanmanın teknik bir kısıtlaması yoktur. Ayrıca function initializer'larını manuel olarak çağırmak da mümkündür ama önerilmez.As a programming convention _VARIABLES method is used for defining members and other required variables and _CONSTRUCTOR method is used to build internal structures of class instance. But there is not a technical constraint to use them different purposes. Also it is possible to call function initializers manually but it is not a recommended.

Normal method'lar ve class initializer'ları arasındaki tek iki ana fark:The only two main difference between regular methods and class initializers:

OBJECT komutu ve scope konusu hakkında detaylar için, lütfen bu kitabın ilgili bölümlerini okuyun.For details about OBJECT command and scope issue, please read the related sections of this book.

Class Instance'ları TanımlamaDefining Class Instances

Bir class instance'ı tanımlamak, bir integer variable tanımlamak kadar basittir. Tek fark "INTEGER" yerine yeni type'ınızı kullanmaktır. İşte "MATHTEST" class'ının bir instance tanımı; GLOBAL, OBJECT, LOCAL gibi tüm data definition komutları için aynıdır.Defining a class instance is as simple as defining an integer variable. The only difference is using your new type instead of “INTEGER”. Here is an instance definition of “MATHTEST” class and it is same for all data definition commands such as GLOBAL, OBJECT, LOCAL etc.

OBJECT:OBJECT:

MATHTEST MATHREC; MATHTEST MATHREC;

Bir class instance'ı tanımlarken, önceki bölümlerde ele alınan tüm variable tanım noktalarını dikkate almalısınız. Ayrıca, bir class instance'ı tanımlamak için bir variable definition komutu çalıştırıldığında, class initializer method'ları tetiklenir. Ama bu method'lar yalnızca bir kez tetiklenir, başka bir deyişle aynı instance birden fazla kez tanımlansa bile class initializer'ları yalnızca bir kez tetiklenir. Bu kural, aynı veya farklı komut instance'ları için de aynıdır. Davranışı doğru anlamak için lütfen aşağıdaki kodun trace'ine bakın:When you defining a class instance you must consider all variable defintion points which are discussed previous sections. Additionally, when a variable definition command executed to define a class instance, class initilalizer methods are fired. But this methods are fired only once, in other words even if same instance are defined more than once class initilizers are fired only once. This rule is same both for same or different command instances. To understand the behavior correctly please see the trace of code below:

OBJECT:OBJECT:

INTEGER NINDEX; INTEGER NINDEX;

NINDEX = 0;NINDEX = 0;

WHILE NINDEX < 2WHILE NINDEX < 2

BEGINBEGIN

OBJECT: OBJECT:

RDTA AREC; RDTA AREC;

OBJECT: OBJECT:

RDTA AREC; RDTA AREC;

NINDEX = NINDEX + 1; NINDEX = NINDEX + 1;

ENDWHILE;ENDWHILE;

Class Method'larını ÇağırmaCalling Class Methods

Class'ların ayrıca bir class instance'ı üzerinden class dışından çağrılabilen method'ları vardır. Bir TROIA Class method'unu çağırmak için özel bir syntax yoktur. Bir class method'unu çağırırken en önemli kısım, class instance ismini belirtmektir, çünkü her instance'ın bir internal state'i olabilir. İşte bir class method'unu çağırmanın basit bir örneği:Classes also have methods that can be called from outside of the class over an class instance. There is a not a special syntax for calling a TROIA Class method. Most important part while calling a class method is specifying class instance name, because each instance can have an internal state. Here is a simple example of calling a class method:

OBJECT:OBJECT:

MATHTEST CLASSINSTANCE, MATHTEST CLASSINSTANCE,

INTEGER RESULT; INTEGER RESULT;

RESULT = CLASSINSTANCE.SUM(5, 6);RESULT = CLASSINSTANCE.SUM(5, 6);

Class method'larını recursive olarak tanımlamak ve diğer class method'larını çağırmak da mümkündür. Class içinde bir class method'unu çağırmak için THIS keyword'ü kullanılır, çünkü class'ın developer'ı class'ın olası instance'larını bilemez. İşte basit bir örnek:It is also possible to define class methods as recursive and call other class methods. To call a class method inside class THIS keyword is used, because developer of class is not able to possible instances of class. Here is a simple example:

/* bu, bir text döndüren bir class method kodudur *//* this is a class method code, which returns a text */

PARAMETERS:PARAMETERS:

INTEGER PA, INTEGER PA,

INTEGER PB; INTEGER PB;

LOCAL:LOCAL:

INTEGER MAXNUM; INTEGER MAXNUM;

/* class'ın MAX adlı başka bir method'u var *//* class have another method named MAX */

MAXNUM = THIS.MAX(PA, PB);MAXNUM = THIS.MAX(PA, PB);

RETURN 'Maksimum sayı ' + MAXNUM;RETURN 'Maximum number is ' + MAXNUM;

Class Member'larına ErişmeAccessing Class Members

Tüm class member'ları class içinde tanımlanır, bu yüzden her class instance'ının her class field'ı için farklı bir memory alanı vardır. Bu yüzden bir class field'ına ismiyle erişmek mümkün değildir, ayrıca instance ismini de belirtmelisiniz. Çoğu programlama dilinde nokta (.) operatörü, programcıların bir class instance'ının field'larına erişmesine olanak tanır. TROIA'da bir field'ın değerine erişmek için @ operatörü kullanılır.All class members are defined inside class, so each class instance has different memory space for each class field. So it is not possible to access a class field with its name, also you must specify the instance name. In most programming languages dot (.) operator, allows programmers to access fields of an class instance. In TROIA @ operator is used to access value of a field.

OBJECT:OBJECT:

STRINGUTIL STRUTIL; STRINGUTIL STRUTIL;

STRUTIL@DEFAULTSEPERATOR = '-';STRUTIL@DEFAULTSEPERATOR = '-';

Tüm member field'ları public olarak kabul edilir, bu yüzden field'lara access modifier'larına göre erişimde bir kısıtlama yoktur. @ operatörü yalnızca bir seviye için kullanılır, bu yüzden 'STRUTIL@MEMBERCLASS@ITSFIELD' geçerli bir kullanım değildir.All member fields are considered as public, so there is not a restriction to access fields by its access modifiers. @ operator is used for only one level, so ‘STRUTIL@MEMBERCLASS@ITSFIELD’ is not a valid usage.

Class InheritanceClass Inheritance

Normal object oriented programlama dillerine kıyasla bazı farklar olsa da, TROIA class'larını inherit etmek ve base class'ın method'larını override etmek mümkündür (dialog'lar için de mümkündür). Class initializer method'larını override etmek desteklenmez; override eden method ve base method sanki tek bir constructor'mış gibi çalıştırılır.Even if there are some differences compared to regular object oriented programming languages, its possible to inherit TROIA classes and override methods of base class (also its possible for dialogs). Overriding class initilizer methods is not supported, if overriding method and base method is executed as if they are a single constructor.

Hem dialog'lar hem class'lar için inheritance, ilerleyen bölümlerde detaylıca ele alınacaktır.Inheritance, both for dialogs and classes will be discussed detailly in next sections.

Alıştırma 1: Class Member'ının Scope'u (Math)Exercise 1: Scope of Class Member (Math)

Şu şekilde bir class tanımlayın:Define a class that:

Tanımdan sonra:After definition:

ve sonuçları karşılaştırın.and compare the results.

Alıştırma 2: Var Olmayan Class Instance'ları TanımlamaExercise 2: Defining Unexisting Class Instances

Undefined bir class ismiyle OBJECT komutunu kullanarak bir class instance'ı oluşturmaya çalışın ve trace'e bakın.Try to create an class instance using OBJECT command with an undefined class name and see the trace.