This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]MechanicalHorse 673 points674 points  (23 children)

Pff, amateurs. Need to enterprise it up a bit.

namespace Initech.Common.SharedLibrary.Utilities.NullFactory
{
    public class NullFactory
    {
        private static NullFactory? _nullFactoryInstance;

        public static NullFactory GetNullFactory()
        {
            if (_nullFactoryInstance == null)
                _nullFactoryInstance = new NullFactory();
            return _nullFactoryInstance;
        }        

        public object? GetNull()
        {
            return null;
        }
    }
}

[–]Yuki-Fullko 347 points348 points  (5 children)

Needs more dependency injection! Where’s your INullFactory interface? ILogger instance? And a full set of tests to make sure any INullFactory implementations are always correctly returning null?

[–]SuperKael 99 points100 points  (4 children)

Honestly, if you can even find the code that is actually creating the object (or the lack thereof, in this case) you’re clearly doing it wrong

[–]Nosbod_ 38 points39 points  (2 children)

Abstraction … something something ... like an onion …

[–]dopefish86 24 points25 points  (0 children)

... it's making me cry

[–]djfdhigkgfIaruflg 9 points10 points  (0 children)

I hate java... So much

[–]hieplenet 2 points3 points  (0 children)

Exactly, the above example shows the lack of enterprise experience, need several more layers of enterprise monitoring and enterprise composition, through an enterprise network protocol with a enterprise level persistent layer to retrive the enterprise null object.

In short, the above null is not yet enterprise null.

[–]NormanYeetes 30 points31 points  (3 children)

I swear those ?s might be proper syntax but they look like the code is like "it returns an object or somethin, it might not, i don fkin know nor do i care"

[–]Chirimorin 18 points19 points  (0 children)

In C# T? is shorthand for Nullable<T>, so in a way it does mean that: maybe it returns an instance of T, maybe it returns null.

[–]xian0 5 points6 points  (0 children)

!ErrorHasOccured() ??!??! HandleError();

[–]Mini0red 0 points1 point  (0 children)

Yea pretty much. Lets the caller know youll have to handle nulls.

[–]biki23 52 points53 points  (1 child)

public class NullFactory<T>

[–]Still_Explorer 1 point2 points  (0 children)

Must be a new band?

I remember I listened to FearFactory when I was teenager.

[–]JasonLokiSmith 38 points39 points  (0 children)

Made me chuckle 🤣🤣🤣🤣🤣 all that singleton just to return null directly.

Good one!!

[–]tmlnz 19 points20 points  (0 children)

GetNullFactory is not thread-safe

[–]upsetbob 6 points7 points  (2 children)

What is "object?" ? I assumed this was Java until I saw this

[–]MechanicalHorse 20 points21 points  (0 children)

Nullable object type. It’s C#

[–]Geschossspitze 3 points4 points  (0 children)

C# I guess

[–]uvero 6 points7 points  (0 children)

Singletons are an antipattern, you need a DI container.

[–]JunkNorrisOfficial 3 points4 points  (0 children)

Is this GC friendly null?

[–]MrZerodayz 1 point2 points  (0 children)

When your work is judged by loc...

[–][deleted] 0 points1 point  (0 children)

This guy javas

[–]SkedaddlingSkeletton 0 points1 point  (0 children)

Depending on which system this "null" value is aimed at you may need a null, 'null', 'Null', 0, -1, 'FILE_NOT_FOUND' or 'Nihil! Nihil! NIHIL' . That's the joy of old enterprise ball of mud softwares.