-2

I have created a 'Database' class, what will be initialize from 'Databaseobject'. So I set the constructor of this database class to internal. Now when I try to initialize this class outside the namespace in another class, Visual studio gives (ofcourse) the message the type 'database' has no constructor defined. The 'database' class has methodes to read/write to the database, so the class itself is public.

This all make sense, its a design decision. My question is, is it possible to give other developers the feedback in Visual Studio that when they try to initialize 'Database' that they must use 'Databaseobject'. I wrote it in the documentation, but some developers (friends) I know don't take the time to read documentation, and when I will go (or thrown, you don't know) out of the company other developers simpley see what the need to do.

Cageman
  • 513
  • 3
  • 22
  • 1
    Other than renaming `Databaseobject` to `DatabaseFactory` I can't think of any other way than documentation. Naming the class `DatabaseFactory` will at least *try* to indicate that some sort of `Factory pattern` is in use here... – Thorsten Dittmar Mar 28 '14 at 11:13
  • It's totally unclear what are you asking for. Class cannot be initialized - object of it can. And if you're thinking about Factory pattern, then I don't think it's the right one to use when defining database context class. – Tarec Mar 28 '14 at 11:15
  • @Tarec Well, if you think about it, what he wants is pretty clear. He wants to document the factory pattern, be it suitable in this case or not. And of course you can't initialize a class, but that is common "talk" really, so try to be a bit flexible ;-) – Thorsten Dittmar Mar 28 '14 at 11:18
  • Thanks Throsten, its a strange factory :p but it is perhaps a better name than I had chosen – Cageman Mar 28 '14 at 11:19
  • 1
    @ThorstenDittmar I did mean to be pinchy. I wrote that, because I think it is importnant for him to distinguish a class from an object. It's extremely confusing, when someone uses 'Databaseobject' as a class name. – Tarec Mar 28 '14 at 11:29

1 Answers1

1

Add the [System.Obsolete("Some message about initialization")] to the 'Database' class.

Its not perfect but it gives a indication on whats going on.

You can write your own attributes using Obsolete as suggested in the answer in this question:

Custom Compiler Warnings

Community
  • 1
  • 1