oop - God object - decrease coupling to a 'master' object -


I have an object called parameter, which is methodically thrown down from the method and at the top of the call tree, into package boundaries is. It is about fifty state variables, each method can use one or two variables to control its output.

I think this is a bad idea, it is possible that I can not easily see which method is needed, or what might be with it, some combination of parameters for module U That is completely unrelated to my current module.

What are some good techniques for reducing the coupling of this god object, or are it ideally destroyed?

  Public Zero ExporterExcelParFonds (ParametresExecution parametres) {ApplicationExcel appExcel = null; LogTool.Instance.ExceptionSoulevee = false; Bowl wrapper reference = parametres.inclureReferences; Bull embrace = parametres.inclureBornes; Date Date Date Debut = parametres.date; Date time datefin = parametres.dateFin; Try {LogTool.Instance.AfficherMessage (Variables.msg_GenerationRapportPortefeuilleReference); Bool fichiersPreparesAvecSucces = PreparationFechners (Parameters, Section Exxcel Topfund); If (! FicturesPeparesAccounts) {parametres.afficherRapportApresGeneration = false; LogTool.Instance.ExceptionSoulevee = True; } Else { 

will be the caller:

  Portfolios context = new portfolios reference (); Pr.ExporterExcelParFonds (parametres);  

First of all, at the risk of being told clearly: pass parameters that Instead, instead of the objects of the deity,

However, it can lead to some parameters because it requires many parameters because they are called other methods, which in turn call other methods, etc. He was probably the inspiration to put everything in the object of God; I will also give a simplified example of such a method with many criteria; You think "lots" here will be here == 3 :-)

  Public Zero PrintFilteredReport (Data Data, Filter Criteria, Report Format Format) {var filteredData = Filter (Data, Criteria) ); Printport (filtered data, format); }  

So the question is, how can we reduce the quantity of standards without the object of the deity? Answer: To get rid of procedural programming and to make good use of object oriented design. Objects that can be used without each other can be used to start their colleagues:

  // data filter service object only needs to know the parameters data data filter = New data filter (criteria); // Report printer service object needs to know only format var report printer = new ReportPrinter (format); // Filtered reporter printer service object is started with // data filter and a report printer service, but it is not needed / to know which parameters they are using for your work FilteredReportPrinter = New FilterteredReportPrinter (datafilter, reportPrinter);  

Now filtered reporter. The print method can only be applied with one parameter:

  Public Zero Print (Data) {var filteredData = this.dataFilter.Filter (info); This.reportPrinter.Print (filteredData); } By coincidence, instead of eliminating the parameters, such isolation of concerns and dependency injection is better if you use collaborative items through the intersection, then make it your class. 

  • Very flexible: You can set the filtering reporting printer with the implementation of a filter / printer
  • Very testable: with fake responses Of fake affiliates Can Ready and can verify that they were used correctly unit test

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -