Classes that represent services or brokers in a Standard-Compliant architecture should represent the type of class in their naming convention, however that doesn't apply to models.
class Student {
...
}class StudentModel {
}In a singular fashion, for any class that contains business logic.
class StudentService {
....
}class StudentsService{
...
}class StudentBusinessLogic {
...
}class StudentBL {
...
}In a singular fashion, for any class that is a shim between your services and external resources.
class StudentBroker {
....
}class StudentsBroker {
...
}In a plural fashion, to reflect endpoints such as /api/students to expose your logic via RESTful operations.
class StudentsController {
....
}class StudentController {
...
}
A field is a variable of any type that is declared directly in a class or struct. Fields are members of their containing type.
Class fields are named in a camel cased fashion.
class StudentsController {
private readonly string studentName;
}class StudentController {
private readonly string StudentName;
}class StudentController {
private readonly string _studentName;
}Should follow the same rules for naming as mentioned in the Variables sections.
When referencing a class private field, use this keyword to distinguish private class member from a scoped method or constructor level variable.
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;
}
}
If the input variables names match to input aliases, then use them, otherwise you must use the aliases, especially with values passed in.
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 (...);