Clean Code - naming related classes [closed] - c#

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I've read Clean Code by R.C. Martin and I'm trying to adopt his suggestions about clean code as broadly as possible.
But I'm not sure how to name related classes.
Let's say I have a class named TreeDirectoryList.
I want to cut implementation of this class into many smaller classes.
Let's say I'll create a class named ParentIndexStack.
ParentIndexStack will implement functionality very dependent on TreeDirectoryList, so it's very not probable that this implementation of ParentIndexStack will be useful with any other class in the future.
But the name of ParentIndexStack is very generic, it's possible, that I'll need another class with the same name, within the same project.
So I thought I'll name ParentIndexStack more precise, like TDLParentIndexStack (prefix TDL is from TreeDirectoryList).
Would it be correct ?
I'll end with many classes starting with TDLxxxxx.

One option is to put that set of classes in their own namespace. Then you can have simple, concise names that still communicate the full meaning of the class through the namespace context.

Related

Page Management in Blazor [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
I've looked around but I can't find anything related to managing your pages; by that I mean, everyone seems to just hardcode their page names and navigations to set pages all over the place.
Is this the recommended way of doing it? Just seems like you will have to do a significant amount of refactoring if things change.
If you guys have a setup you really like, I would love to hear about it :)
I've considered making a static lookup class, that can provide all the page paths and their equivalent navigations, but I don't know if it is an absolute overkill.
You can use reflection. Remember, each .razor file you create for a Blazor page will have the class generated for it that is the same as the name of the file. You can create a base class called BasePage and do #inherits BasePage on each of your pages. Then you have a singleton service that uses reflection to find all these classes and keep track of them that way.

Define constants needed in more than one class [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
In my smart client solution, I have a Project folder with:
IProjectView.cs
*ProjectView*
ProjectView.cs
ProjectView.Designer.cs
ProjectView.GeneratedCode.cs
ProjectView.resx
ProjectViewPresenter.cs
I want to define some constants for user by ProjectView.cs and ProjectViewPresenter.cs. Both of these classes implement IProjectView.cs, so were I back in Java, I'd put them there. If this were C++, I'd create a class ProjectConstants.cs and have the classes inherit it, but C# doesn't allow multiple inheritance.
How do I do this?
Can having a Read-Only Property in your interface solve your problem?
string MyReadOnlyProperty { get; }
I have no clue if this is very performance-wise compared to constant thought.

c# mapping class to another class [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am interested in best design pattern on below issue. Say I have 2 classes with different number of properties. I need to map instance of source class to target class' instance. Mapping source property may not be simply as just equal. There may conditional check and etc. As simplest way would be writing method and accept source class'object as parameter. Then manipulate properties and initialize target class' object. However it is not good, as there will be duplicate code and logic. Because there are will be many type of source classes. So, I will be forced writing code fach convertion. Something comes to my mimd generic methods? Thanks for your time.
Automapper worked fine for our team.

C# method naming best practices [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I have a coworker that keeps renaming object and method in my code. Add S, removing S etc..
I would like to know what is the best way in your opinion.
Suppose I have a class Client.
This Client can set two reminders (wakeupReminder and leaveReminder).
Each of these reminders have different settings.
So I created a Class called WakeUpReminderSettings. He told me that I should rename it to WakeUpReminderSetting because it is not a collection.
I also created a method that return all reminders settings. I named it GetClientRemindersSettings.
Again, he renamed it to GetClientReminderSettings. He's argument: Only the last word should be pluralized..
I would like to have your thoughts on this.
I think you're right in both cases. A WeakUpReminderSettings can be an aggregate of different settings without being a collection, and if your method return settings for multiple reminders, it makes sense to pluralize reminder even if it's not the last work.
Then again, naming conventions are really something subjective, if your coworker is not above you in the hierarchy, I'd tell him to stop messing with your work for minor changes like this.

Is "massive" usage of #region considered a bad practice? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
My MainViewModel has to deal with a lot of commands with complex actions inside, therefore its extension has grown inevitable. For keep the code organized I tend to use #region to group similar o related tasks.Does this considered an overuse of this feature or it's perfectly normal? You may say that it depends on me, if I feel right about it. I think that it helps a lot but I would like to know what do others. Here is a screenshot of how the code look like:
The bad practice is a massive single class. #region is simply hiding / coping with it.
If there are groups of methods, delegate them to another class.

Categories

Resources