Is the facade template only static functions an unnecessary layer

I am currently using IKVM to access a large Java library in a C # .Net project. The entry point to the library is singleton, and from there I can create objects and set properties of objects.

Currently, I have created a C # facade template around this singleton and am creating an object and passing parameters through this Facade. The functions in Facade are all static. Is it normal that the facade template contains only static functions, or did I just create an extra layer with a very small value?

The original Java code looks something like this:

Code code = Singleton.Instance.CreateCode(); code.SetExtension("12345"); code.SetId("1"); SubCode subCode = Singleton.Instance.CreateSubCode(); subCode.SetRoot("6789"); subCode.SetId("2"); code.SetSubCode(subCode); 

A simplified (without error checking) version of C # looks something like this:

 public static FacadePattern { public static Code CreateCodeWithSubCode(string extension, string codeId, string root, string subCodeId) { Code code = Singleton.Instance.CreateCode(); code.SetExtension(extension); code.SetId(codeId); SubCode subCode = Singleton.Instance.CreateSubCode(); subCode.SetRoot(root); subCode.SetId(subCodeId); code.SetSubCode(subCode); return code; } public static CreateCodeForHP(string extension, string codeId) { Code code = Singleton.Instance.CreateCode(); code.SetExtension(extension); code.SetId(codeId); code.SetUse(com.org.vocabulary.HP); return code; } } 
+4
source share
1 answer

No, there is nothing wrong with static methods. You do not need an object, you are just trying to hide the implementation of getting what you want. If you intend to use this method more than once, leave it, you will save 8 - 10 lines of code each time, making it more stable and supported.

If you are not going to reuse it, just set the body of the method where you need it.

+3
source

Source: https://habr.com/ru/post/1493908/


All Articles