Getting lost in the OOP chest when trying to put the method in the right place, etc.

It’s not like I don’t understand the concept of OOP and what needs to be done when, but sometimes I just get mentally lost in it.

Which is better from the example? Therefore, I needed to upload the file to a temporary path, I decided to get the temporary path using non-ordinary dot net methods due to an irrelevant reason. So I wrote my own method for doing this string GetTempFileSafe(string extension, out FileStream), good, right? But hey, wait, this is not the right place for this method ... This method can be used for other things. It must be a static public method somewhere. but where? Well, I think I will need to open a new static class for it. Hopefully I will add some more methods the other day.

So, I defined public static class FileStreamUtils \\one hell of a name huh?and added my method to it. But hold on ... Where should this class be? Basically, I can use any project ... it has nothing to do with this particular one. So I opened a whole new library that I called MyUtils.

I added my static class with my only static method to it, built a library, added a dll as a reference to my original project ... and that. (note that the method is harder to debug, because I use dll instead of the source code)

Now don't get me wrong. I literally love OOP concepts and accuracy, but sometimes it just makes me up. Perhaps because I all work independently.

? , , , , ? , ( , , , , - , )?

. , , - , , , , .

+5
6

, , , . , , , , - , , , , , .

, , Helper. , , - . , .

0

-, #, , Java, , , , ...

Java "". , IDE .., .

, , , , , , . , . , , .

, , .., .

, , .

, . . ( " ", , , .)

, , # , "".

0

:

, , , . , ( ) , , - , , , . .

, , , , , , .

0

, , , .

OO , , , .

, , BCL, .

: GetTempFile System.String FileStream, - , ?

, , "" , , :

public class Extension
{
    private readonly string extension;

    public Extension(string extension)
    {
        // Guard Clauses go here
        this.extention = extension;
    }

    public string GetTempFileSafe(out FileStream)
    {
        // implementation goes here, using this.extension...
    }
}

As a next step, you can modify this API to get rid of the parameter outby encapsulating the resulting string and FileStream in a new object.

-1
source

All Articles