Click here to Skip to main content
15,885,244 members
Home / Discussions / Design and Architecture
   

Design and Architecture

 
QuestionDilemma on exposing methods in interface based programming Pin
SSEAR22-Apr-12 23:11
SSEAR22-Apr-12 23:11 
AnswerRe: Dilemma on exposing methods in interface based programming Pin
VallarasuS24-Apr-12 5:12
VallarasuS24-Apr-12 5:12 
AnswerRe: Dilemma on exposing methods in interface based programming Pin
jschell28-Apr-12 7:52
jschell28-Apr-12 7:52 
GeneralRe: Dilemma on exposing methods in interface based programming Pin
SSEAR29-Apr-12 20:53
SSEAR29-Apr-12 20:53 
GeneralRe: Dilemma on exposing methods in interface based programming Pin
jschell30-Apr-12 8:00
jschell30-Apr-12 8:00 
GeneralRe: Dilemma on exposing methods in interface based programming Pin
SSEAR1-May-12 20:28
SSEAR1-May-12 20:28 
GeneralRe: Dilemma on exposing methods in interface based programming Pin
jschell2-May-12 10:57
jschell2-May-12 10:57 
AnswerRe: Dilemma on exposing methods in interface based programming Pin
BobJanova30-Apr-12 4:06
BobJanova30-Apr-12 4:06 
I don't understand what the problem with allowing users to create instances of their classes directly is. (Users in this case meaning users of the framework; that could well be you as well.)

The important thing about interface based programming is that the core code, including the dependency injection mechanism if you want such a thing, deal with the interfaces. Methods in your core logic should take and return interfaces, not concrete subclasses; this makes them easily mockable and re-usable. But there's no reason to try to prevent someone from declaring a Class1 which implements one of the public interfaces and creating it directly; sometimes that's actually what you need in a specific case.

You should advise your users (again, that might be yourself or other team members) that generally it's better to use the interfaces and get a resolved instance from the container, but that should be 'enforced' with coder discipline, not a technical solution.

A final point is that it is essentially impossible to provide an extensible container, which allows registration of arbitrary classes, and also to prevent people instantiating those classes directly, because the container needs to use a constructor to resolve a request. You could require that a factory class is passed instead, but that's abstraction for the sake of it, and if it's a user specified factory, they can just call the factory method directly anyway.
GeneralRe: Dilemma on exposing methods in interface based programming Pin
SSEAR1-May-12 21:01
SSEAR1-May-12 21:01 
GeneralRe: Dilemma on exposing methods in interface based programming Pin
jschell2-May-12 11:07
jschell2-May-12 11:07 
QuestionWhen we will stop programming?! PinPopular
Hasan Al-Halabi8-Apr-12 0:25
Hasan Al-Halabi8-Apr-12 0:25 
AnswerRe: When we will stop programming?! Pin
Eddy Vluggen8-Apr-12 0:30
professionalEddy Vluggen8-Apr-12 0:30 
GeneralRe: When we will stop programming?! Pin
Hasan Al-Halabi8-Apr-12 1:14
Hasan Al-Halabi8-Apr-12 1:14 
AnswerRe: When we will stop programming?! Pin
Eddy Vluggen8-Apr-12 1:39
professionalEddy Vluggen8-Apr-12 1:39 
QuestionRe: When we will stop programming?! Pin
Hasan Al-Halabi8-Apr-12 3:25
Hasan Al-Halabi8-Apr-12 3:25 
AnswerRe: When we will stop programming?! Pin
Eddy Vluggen8-Apr-12 8:37
professionalEddy Vluggen8-Apr-12 8:37 
AnswerRe: When we will stop programming?! Pin
Hasan Al-Halabi9-Apr-12 11:52
Hasan Al-Halabi9-Apr-12 11:52 
AnswerRe: When we will stop programming?! Pin
Hermaine18-Apr-12 21:24
Hermaine18-Apr-12 21:24 
GeneralRe: When we will stop programming?! Pin
Hermaine18-Apr-12 21:23
Hermaine18-Apr-12 21:23 
GeneralRe: When we will stop programming?! Pin
Eddy Vluggen19-Apr-12 6:50
professionalEddy Vluggen19-Apr-12 6:50 
AnswerRe: When we will stop programming?! Pin
Pete O'Hanlon8-Apr-12 2:25
mvePete O'Hanlon8-Apr-12 2:25 
GeneralRe: When we will stop programming?! Pin
Hasan Al-Halabi8-Apr-12 3:23
Hasan Al-Halabi8-Apr-12 3:23 
GeneralRe: When we will stop programming?! Pin
Pete O'Hanlon8-Apr-12 11:32
mvePete O'Hanlon8-Apr-12 11:32 
AnswerRe: When we will stop programming?! Pin
Rustem Gaifutdinov24-Apr-12 3:52
Rustem Gaifutdinov24-Apr-12 3:52 
AnswerRe: When we will stop programming?! Pin
Midnight Ahri27-Apr-12 15:10
Midnight Ahri27-Apr-12 15:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.