Xizmatlar(service) va vositachilarni(broker) ifodalovchi sinflar(class) Standartga amal qilingan arxitekturada tiplarni nomlashdagi qoidalariga binoan ifodalashi kerak, ammo bu qoidalar modellar uchun amal qilinmaydi.
class Student {
...
}
class StudentModel {
}
Birlikda, biznes logikani o'z ichiga olgan istalgan sinf(class) uchun
class StudentService {
....
}
class StudentsService{
...
}
class StudentBusinessLogic {
...
}
class StudentBL {
...
}
Birlikda, sizning xizmatlaringiz(service) va tashqi resurslar orasini ajratuvchi istalgan sinf uchun
class StudentBroker {
....
}
class StudentsBroker {
...
}
Ko'plikda, oxirgi nuqtalar(endpoint)larni aks ettirishda, masalan RESTful amallar orqali dastur mantig'ini(logic) ifodalovchi api/students
kabi
class StudentsController {
....
}
class StudentController {
...
}
Maydon sinf(class) va tuzilma(struct) ichida e'lon qilingan istalgan tipdagi o'zgaruvchi
Sinf(class) maydonlari(field) camel case usulida nomlanadi.
class StudentsController {
private readonly string studentName;
}
class StudentController {
private readonly string StudentName;
}
class StudentController {
private readonly string _studentName;
}
Nomlashda O'zgaruvchilar(Variable) bo'limidagi aytilgan qoidalarga amal qilish kerak
Classning private maydoniga yo'llanma berayotganda classning private a'zosini scoped metodlar va konstruktor miqyosidagi o'zgaruvchilardan farqlash uchun this
kalit so'zidan foydalaning.
class StudentsController {
private readonly string studentName;
public StudentsController(string studentName) {
this.studentName = studentName;
}
}
class StudentController {
private readonly string _studentName;
public StudentsController(string studentName) {
_studentName = studentName;
}
}
Agar kiruvchi o'zgaruvchilar nomi parameter nomi bilan to'g'ri kelsa to'g'ridan-to'g'ri o'zgaruvchilarni ishlating. Agar aksincha bo'lsa parameter nomi bilan ishlatishingiz kerak, xusuan qiymatlar bilan.
int score = 150;
string name = "Josh";
var student = new Student(name, score);
var student = new Student(name: "Josh", score: 150);
var student = new Student("Josh", 150);
Student student = new (...);
Sinfdan(class) namuma(instance) yaratayotganda xossalar berishdagi ketma-ketlik sinf(class)ni e'lon qilgandagi xossalar ketma-ketligi bilan bir xil bo'lishiga amin bo'ling
public class Student
{
public Guid Id {get; set;}
public string Name {get; set;}
}
var student = new Student
{
Id = Guid.NewGuid(),
Name = "Elbek"
}
public class Student
{
private readonly Guid id;
private readonly string name;
public Student(Guid id, string name)
{
this.id = id;
this.name = name;
}
}
var student = new Student (id: Guid.NewGuid(), name: "Elbek");
public class Student
{
public Guid Id {get; set;}
public string Name {get; set;}
}
var student = new Student
{
Name = "Elbek",
Id = Guid.NewGuid()
}
public class Student
{
private readonly Guid id;
private readonly string name;
public Student(string name, Guid id)
{
this.id = id;
this.name = name;
}
}
var student = new Student (id: Guid.NewGuid(), name: "Elbek");
public class Student
{
private readonly Guid id;
private readonly string name;
public Student(Guid id, string name)
{
this.id = id;
this.name = name;
}
}
var student = new Student (name: "Elbek", id: Guid.NewGuid());