c# - Using Interfaces in Webforms -


I usually make an external class library for my ASP.NET projects, I refer to the project But I'm working on one of the webforms, I will create that class object and use the code behind its properties and methods:

  user usr = new user (); Usr.Username = "username"; Usr.Password = "password"; Usr.Register ();  

I am currently working with one of my colleagues who call 'bad design', especially when I make a class diagram for him. According to them, they say that this "bad design / programming is directly in the code behind a webform's file." They say that I should use the interface instead, so if there is a change in the class library then my The application will not complain about any disturbance on the front end, which means that I do not have to change anything on the front end. String user name "to" public string user ", then I should not give any error in front, some code independence or something like this:

  interface IU = new user (); IU Username = "Username"; IU.Password = "Password"; IU.Register ();  

This is for my own understanding, but I verified it to someone and

always feedback and best It's a matter of tampered practice.

Personally I do not see anything in creating an interface for your domain objects (with its obvious exception, it acts as a common contract between two domain objects is).

While the interface is very useful, instead of creating the interface representing the IUser between layers, I will declare an interface for the register method.

This is where the design is changing, you are declaring your register method as part of the user. This is a normal pattern that is known as an active record. Personally I do not like this approach for some reasons:

  • It puts data access codes into your domain objects (and So all the way from your solution)
  • It often requires every part of your solution in terms of every other.

There will be a user class for my suggestion, which is passed in the business logic class with a register () method. This business logic class will then apply to IManagerUsers (or whatever you want to call it).

  public class user {public string user name {get; Set;} public string password {get; Set;}} Public Interface IUserManager {bool register (user user); } Public class UserManager: iUserManager {public bool register (user user) {// register your user here}}  

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -