Learn how to design an application architecture [closed]

Closed. It is impossible to give an objective answer to this question . Answers to it are not accepted at the moment.

Want to improve this question? Reformulate the question so that it can be answered based on facts and quotations.

Closed 5 years ago.

Improve the question

I began to notice that as I mastered C#, I began to think more and more about how to architecturally implement this or that part applications.

For example, when developing an application for interacting with a USB device, I thought about how exactly its components would interact.

For example, you can implement a single class that will do everything: work at the WinAPI level with USB, wait for packets to arrive, understand the communication protocol, implement command sequences and process responses to them, etc.

But this is an inconvenient solution. It is better to divide by layers and, for example, make communication via USB in a separate module and then, if USB is changed to Ethernet, you can just write a new module, without touching the rest.

Okay, we're writing a USB communication module. To do this, we first write the interface for interacting with the upper level. They wrote it. So, something here is all sharpened for synchronous exchange, and suddenly you need an asynchronous one. We supplement it. And a few more parameters.

We start writing the module itself. It turns out that the built-in functionality is redundant. And also there's something wrong here and there, etc. Again, we begin to think, correct/supplement.

As a result, I dig into the questions from the series "what is the best way to do it now, so that it will be convenient to maintain it in the future?", performance drops, and the complexity of the invented designs increases dramatically, and as a result, some kind of porridge is obtained, and not the perfect code that I wanted to get.

What am I doing wrong? What do experienced programmers do? How do they avoid these endless questions and still write completely supported and understandable code?

What kind of literature can you read to improve yourself in these matters? Design patterns? Aren't they too tailored for large projects and too complex for small projects?

And does anyone have links to C# projects where you can view architectural solutions?

Author: Kyubey, 2014-03-25

3 answers

@yabloko, the ability to design and find a balance between the current needs of the project and creating a foundation for the future comes only with experience. You can't just read a book and become enlightened. Therefore, write code, think about it, study how other people's projects work, and model some examples taken from the ceiling. Design small "taken from the ceiling" pieces of functionality for the warm-up. Just on a piece of paper. For example:

  • simple UI of text fields and buttons, but such that you can expand the number of widgets if necessary;
  • contact list, with the ability to import from different sources (mail, twitter, social networks);
  • a text editor with simple operations on the text (for example, making the selected fragment a CAP) and the ability to cancel them.
  • , etc.

In general, fantasize and train.

By the way, about designing a full-fledged text editor, it is chewed in detail in the " Gang four."

 4
Author: Nofate, 2014-03-25 19:38:10

Try to think in terms of entities and their responsibilities. What entities are there in your program, who is responsible for what, who knows what? If you can't describe the responsibility of a module/class/function/variable in one short sentence, you may need to redo it.

You don't have to think about whether you will need to swap a piece with USB for a piece with Ethernet. This may prove to be a premature design decision, overengineering. But here is the division into separate simple layers - the right idea, it will help you to deal with the complexity of the project, to focus each time only on the right part.

Similarly, you allocate code to a procedure if it makes sense on its own, not for reuse. Even if the procedure is used only once.

It's worth reading a book on patterns, but don't get too carried away with it: your brains are better than canned ideas. Moreover, the fact that in one language - a pattern, in another part syntax (example: Observer in C# is implemented in a single declaration, and in C++ requires a lot of boilerplate code).

 3
Author: VladD, 2014-03-26 00:32:08

Read about programming patterns. For example, there is a little book "Design Patterns" by Eric Freeman, Elizabeth Freeman, where everything is shown in Java, but the essence is clear for other languages. There is also a lot of literature on patterns. use them, practice, and there will gradually come an understanding of what to do and how to do it.

 0
Author: Morgot, 2014-03-27 06:01:16