C # - separate user interface from business code

I want to know what works best for the following case:

I am developing an application that needs to be used on three different screen sizes: 240x320; 800x600 1280x1024 (and only these three) in different languages ​​(using localization).

So, I did to create a library to fit the screen, each of which implements the interface defined in the project that calls up these screens.

The first question is that all my resource files are duplicated, and this is a lot of files to update (or with duplicate labels). Is there an easy way to change this?

Second question: am I taking a good approach or is there a better way to do what I'm trying to do? Using a design template, perhaps?


Code example

Caller Code:

public int X { get { return 800; } } public int Y { get { return 600; } } public interface IScreenForm { Form FormComponent { get; } } public interface IFormA : IScreenForm { TextBox UserTextBox { get; } // For use } public void LoadForm<T>() where T:IScreenForm { if (!typeof(T).IsInterface) { throw new ArgumentException(typeof(T).Name + " is not an interface"); } Assembly screenAssembly; string screenResolutionDll = string.Format("{0}_{1}_screens.dll", this.X, this.Y); screenAssembly = Assembly.LoadFrom(screenResolutionDll); Type formType = screenAssembly.GetTypes() .FirstOrDefault(t => t.GetInterfaces().Where(i => i.Name == typeof(T).Name).Count() > 0); if (formType != null) { Form form = (Form)formType.GetConstructor(new Type[] { }).Invoke(null); if (form != null) { form.Show(); } else { throw new ArgumentException("Form doesn't provide a new() ctor"); } } else { throw new ArgumentException("Any form doesn't implement the interface : " + typeof(T).Name); } } 

DLL screen:

 public partial class MyFirstForm : Form, caller.IFormA { public Form1() { InitializeComponent(); } /* caller.IFormA interface implementation */ } 
+4
source share
2 answers
Arno, from my own experience, from reading and from conversations with experienced developers: when it comes to supporting multiple screen sizes and with localization, there are no magic bullets. For localization, put all your lines in resource files or even data files.

Regarding screen sizes, I would not become too smart. Yes, make sure that none of your business / non-graphical interfaces are duplicated, but duplicate resource files, forms, etc. “I wouldn't worry about that.” Some graphical interfaces, such as Qt and GTK with automatic resizing and automatic layout of graphical GUI widgets (for example, Qt has spacer widgets). It works fine most of the time, but I still prefer explicit control. When programming the GUI, unexpected crashes often occur, having three independent sets of GUI components that will allow you to access them if they occur. Some examples of sources of problems: 1) Font size. 2) Windows availability settings. 3) Some national languages ​​have longer average words than others; long words have problems with accommodation in existing real estate.

If I were in your place, I would look, for example, how browsers deal with this (for example, the mobile version or the desktop version), and I will try to find some practical tips on the Internet (for example, here in SO). I doubt that books on design patterns will be very helpful. Disclaimer: I am a skeptic with a design pattern.

+3
source

It is difficult to consult without getting the whole picture, but for some tips that could read it with ease.

http://msdn.microsoft.com/en-us/library/ff648753.aspx

About SmartClient Factory Software.

It comes with architectural guides and solutions that you often see in such applications.

+1
source

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


All Articles