interface - How to Call this C# Class (PropertyRepository class) Method -


I am studying this method and I want to execute a method but I do not know when to call from The parameterized constructor seems to be so complicated for me that the code I follow is made up of two interfaces and two sections. Below is the sample code. Please help me to call "TestMethod ()". If possible, someone can help me with the following goals.

  1. Call "TestMethod ()".
  2. Explain this pattern and its importance (if simplicity is better then help simplify them).
  3. Explain what constellation parameters are (if simplicity is better, please help simplify them).

    Console Application

      Class Program {Private Static IPO Service _property; Public Program (IPParty Service Service) {_property = property; } Fixed Zero main (string [] args) {Console.WriteLine ("Enter something ..."); _property.TestMethod (Console.ReadLine ()); Console.ReadLine (); } Public Interface IPropertyService {string TestMethod (string strParam); } Private class Property Service: IPProtiti Service {Private Readonly IP Reporter _Property Repository; Public Property Service (IPprotectResponsible Property Repository) {_propertyRepository = propertyRepository; } Public string testmap (string straddle) {return_property repository test method (strParam); }}} Public Interface IPropertyRepository {string TestMethod (string strParam); } Public Class Property Resository: IPPrealty Repository {public string testament (string string) {return string format ("You have entered: {0}", Stampam); }}    

    The program is your entry point square, do not create this parameterized constructor, it will not work .

    . Announce it locally inside the main method and it will be fine.

      Fixed zero main (string [] args) {Console.WriteLine ("enter something ..."); IPropertyService _property = // is to be added; _property.TestMethod (Console.ReadLine ()); Console.ReadLine (); }   

    Now let's talk about the // link to the section.

    In this case, the easiest solution is to use so far. Example for manual coded:

      Public class PropertyServiceFactory {Create Public IPproti Services (IP) • Rectangular Repository • New Property Ripatory (); Estate Service Services = New Property Services (Stores); Return service; }}   

    Implementation:

      console WrightLine ("Enter something ..."); PropertyServiceFactory factory = New PropertyServiceFactory (); IPPrint service_property = factory Create (); _property.TestMethod (Console.ReadLine ());   

    However if you want to break the dependency between PropertyServiceFactory and PropertyRepository, then change your factory to:

      public class PropertyServiceFactory {Private Redoni IPProperty Repository _respotry; Public PropertyServiceFactory (IPropertyRepository repository) {_repository = repository} Create Public IPropertyService () {PropertyService Service = New PropertyService (_repository); Return service; }}   

    with it you have decoded PropertyServiceFactory and PropertyRepository. The implementations are as follows:

      console WrightLine ("Enter something ..."); IPPropi repository repository = new property registrar (); PropertyServiceFactory factory = New PropertyServiceFactory (stores); IPPrint service_property = factory Create (); _property.TestMethod (Console.ReadLine ());   

    Credit for Mark Simon

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -