Mid Term exam, Topic 2 b) Design Review

Banashri
Windoof-User
Windoof-User
Beiträge: 25
Registriert: 19. Dez 2013 02:55

Mid Term exam, Topic 2 b) Design Review

Beitrag von Banashri »

Hi,
Can anyone explain me how DIP violated in the UML diagram for DungeonGame?
I cannot see any problem between relationship of Position and Character classes.

Edited: If Position is a class, then direct use of it inside methods of Characters makes it dependent on low level details. Thus, DIP violated can be justified. But, in that case, ISP violation cannot be justified for Position, for being it a class.

Can anyone has solution that Prof. explained?

FabianG
Erstie
Erstie
Beiträge: 14
Registriert: 22. Okt 2012 00:05

Re: Mid Term exam, Topic 2 b) Design Review

Beitrag von FabianG »

Banashri hat geschrieben:Edited: If Position is a class, then direct use of it inside methods of Characters makes it dependent on low level details. Thus, DIP violated can be justified. But, in that case, ISP violation cannot be justified for Position, for being it a class.
As far as i can see, Position is a class. I was not there when the mid term exam was discussed so maybe i am wrong but i would say DIP is justified because of what you said. An ISP violation can be found at a different spot (e.g. PeacefulMob depends on the method attack(...) which it does not need)

ayushmaan_jain
Mausschubser
Mausschubser
Beiträge: 64
Registriert: 18. Okt 2014 11:11

Re: Mid Term exam, Topic 2 b) Design Review

Beitrag von ayushmaan_jain »

I might be wrong but as per my understanding, character class is using Object of Position class directly.
It should not do that as per principle of DI which states high level policy should not depend on low level policy but both should depend on abstraction.
So, I think there should be an abstraction level between Position & Character. Recall, the lamp/button example.

ayushmaan_jain
Mausschubser
Mausschubser
Beiträge: 64
Registriert: 18. Okt 2014 11:11

Re: Mid Term exam, Topic 2 b) Design Review

Beitrag von ayushmaan_jain »

And professor told that Position violates ISP that I dont understand, how ?

JohannesRudolph
Windoof-User
Windoof-User
Beiträge: 31
Registriert: 7. Nov 2010 01:42

Re: Mid Term exam, Topic 2 b) Design Review

Beitrag von JohannesRudolph »

ayushmaan_jain hat geschrieben:And professor told that Position violates ISP that I dont understand, how ?
If that's what was said in the lecture, I must disagree.

A violation of ISP often goes hand in hand with a violation of SRP, i.e. a class that has multiple responsibilities may easily have clients using non-intersecting subsets of its methods. I cannot see this is the case here with the position class, the methods offered by it look quite cohesive to me. And we don't know for sure what metjods the Characters need from it to carry out their game logic.

DIP isn't violated by Position either, or can you tell me why it would be likely that you would want to swap out the implementation of position? This is a very unlikely axis of change and needlessly complicates the design. But you can mention it anyway.

Note that in one of the earlier trial exams (the one with the Document hierarchy and File class) the case looked similar but was quite different (in my opinion anyway). The File class offered a lot of detail methods (e.g. delete, getParent) that I think were clearly not used so it violates ISP. Introducing an interface here that File implements helps fix ISP and also makes it nicer with regards to DIP too.

The big problem with those UML exercises in my opinion is that the examples are quite arbitrary and you can pretty much make up good arguments for almost anything given enough time. The way I approach them is to find a potential violation for each SOLID principle and then argue whether I think it is severe enough to require adjustment (and then do so).

Antworten

Zurück zu „Archiv“