Subject of Observer design pattern an interface or a super class?











up vote
2
down vote

favorite












I'm studying design patterns from a course at coursera. They have there course notes in which they define the Subject of the observer design pattern as super class as shown in the image and code below



UML
enter image description here



CODE (SUBJECT)
enter image description here



Now I think the Subject class is useless by itself until a subclass inherit from it and make any specific subject. In that case shouldn't the Subject be a java interface instead ? What is the reason that the Subject is not a java interface but the Observer is.



Is there any specific reason for that. I'm a little confused about this.



Thanks










share|improve this question






















  • I think the Subject class is useless by itself until a subclass inherit from it and make any specific subject- Why is that?
    – user7
    Nov 10 at 13:57










  • @user7 because what else is it doing other than attaching and detaching observers and keeping a list of them which is eventually going to be present in sub classes when we will inherit from the subject in other words now the sub classes have the same same code after inheriting plus there own additional code so wouldn't it be same if subject was an interface and classes implement that functionality ?
    – Syed Ahmed Jamil
    Nov 10 at 14:10















up vote
2
down vote

favorite












I'm studying design patterns from a course at coursera. They have there course notes in which they define the Subject of the observer design pattern as super class as shown in the image and code below



UML
enter image description here



CODE (SUBJECT)
enter image description here



Now I think the Subject class is useless by itself until a subclass inherit from it and make any specific subject. In that case shouldn't the Subject be a java interface instead ? What is the reason that the Subject is not a java interface but the Observer is.



Is there any specific reason for that. I'm a little confused about this.



Thanks










share|improve this question






















  • I think the Subject class is useless by itself until a subclass inherit from it and make any specific subject- Why is that?
    – user7
    Nov 10 at 13:57










  • @user7 because what else is it doing other than attaching and detaching observers and keeping a list of them which is eventually going to be present in sub classes when we will inherit from the subject in other words now the sub classes have the same same code after inheriting plus there own additional code so wouldn't it be same if subject was an interface and classes implement that functionality ?
    – Syed Ahmed Jamil
    Nov 10 at 14:10













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I'm studying design patterns from a course at coursera. They have there course notes in which they define the Subject of the observer design pattern as super class as shown in the image and code below



UML
enter image description here



CODE (SUBJECT)
enter image description here



Now I think the Subject class is useless by itself until a subclass inherit from it and make any specific subject. In that case shouldn't the Subject be a java interface instead ? What is the reason that the Subject is not a java interface but the Observer is.



Is there any specific reason for that. I'm a little confused about this.



Thanks










share|improve this question













I'm studying design patterns from a course at coursera. They have there course notes in which they define the Subject of the observer design pattern as super class as shown in the image and code below



UML
enter image description here



CODE (SUBJECT)
enter image description here



Now I think the Subject class is useless by itself until a subclass inherit from it and make any specific subject. In that case shouldn't the Subject be a java interface instead ? What is the reason that the Subject is not a java interface but the Observer is.



Is there any specific reason for that. I'm a little confused about this.



Thanks







java oop design-patterns uml






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 13:53









Syed Ahmed Jamil

174214




174214












  • I think the Subject class is useless by itself until a subclass inherit from it and make any specific subject- Why is that?
    – user7
    Nov 10 at 13:57










  • @user7 because what else is it doing other than attaching and detaching observers and keeping a list of them which is eventually going to be present in sub classes when we will inherit from the subject in other words now the sub classes have the same same code after inheriting plus there own additional code so wouldn't it be same if subject was an interface and classes implement that functionality ?
    – Syed Ahmed Jamil
    Nov 10 at 14:10


















  • I think the Subject class is useless by itself until a subclass inherit from it and make any specific subject- Why is that?
    – user7
    Nov 10 at 13:57










  • @user7 because what else is it doing other than attaching and detaching observers and keeping a list of them which is eventually going to be present in sub classes when we will inherit from the subject in other words now the sub classes have the same same code after inheriting plus there own additional code so wouldn't it be same if subject was an interface and classes implement that functionality ?
    – Syed Ahmed Jamil
    Nov 10 at 14:10
















I think the Subject class is useless by itself until a subclass inherit from it and make any specific subject- Why is that?
– user7
Nov 10 at 13:57




I think the Subject class is useless by itself until a subclass inherit from it and make any specific subject- Why is that?
– user7
Nov 10 at 13:57












@user7 because what else is it doing other than attaching and detaching observers and keeping a list of them which is eventually going to be present in sub classes when we will inherit from the subject in other words now the sub classes have the same same code after inheriting plus there own additional code so wouldn't it be same if subject was an interface and classes implement that functionality ?
– Syed Ahmed Jamil
Nov 10 at 14:10




@user7 because what else is it doing other than attaching and detaching observers and keeping a list of them which is eventually going to be present in sub classes when we will inherit from the subject in other words now the sub classes have the same same code after inheriting plus there own additional code so wouldn't it be same if subject was an interface and classes implement that functionality ?
– Syed Ahmed Jamil
Nov 10 at 14:10












2 Answers
2






active

oldest

votes

















up vote
4
down vote



accepted










Observer D P is a simple.




  1. The Subject is the entity that the Observer watches.


  2. The Subject is single entity and the Observers can be more than one.


  3. The Subject has the List observers, but the Observer will have the Subject.


  4. Any change in the Subject will be notified to all the observers that the Subject stores in the form of a list.


  5. We can have the Subject as interface too. All depends on way we implement the above points.



enter image description here






share|improve this answer





















  • Thanks, I guess you are right. Implementation can vary as long as all the points holds true.
    – Syed Ahmed Jamil
    Nov 10 at 14:15










  • you are welcome buddy :) Glad could help.
    – janardhan sharma
    Nov 10 at 14:19


















up vote
5
down vote













If Subject was an interface, then every class that implements Subject must re-implement all the registerObserver, unregisterObserver, and notify methods which are very standard.



You may say that you will put those methods into a helper class so that every derived Subject can just delegate the tasks to this helper. But after all, you have to duplicate the delegation code for all derived Subject classes. Althought the delegation code is short and straight-forward, that duplication is still frustrating.



You can find that argument near the end of this very interesting article of Uncle Bob: http://blog.cleancoder.com/uncle-bob/2015/01/08/InterfaceConsideredHarmful.html






share|improve this answer























  • Thanks that was a nice and funny read answered a lot of other frustrating questions
    – Syed Ahmed Jamil
    Nov 11 at 19:01











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239652%2fsubject-of-observer-design-pattern-an-interface-or-a-super-class%23new-answer', 'question_page');
}
);

Post as a guest
































2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
4
down vote



accepted










Observer D P is a simple.




  1. The Subject is the entity that the Observer watches.


  2. The Subject is single entity and the Observers can be more than one.


  3. The Subject has the List observers, but the Observer will have the Subject.


  4. Any change in the Subject will be notified to all the observers that the Subject stores in the form of a list.


  5. We can have the Subject as interface too. All depends on way we implement the above points.



enter image description here






share|improve this answer





















  • Thanks, I guess you are right. Implementation can vary as long as all the points holds true.
    – Syed Ahmed Jamil
    Nov 10 at 14:15










  • you are welcome buddy :) Glad could help.
    – janardhan sharma
    Nov 10 at 14:19















up vote
4
down vote



accepted










Observer D P is a simple.




  1. The Subject is the entity that the Observer watches.


  2. The Subject is single entity and the Observers can be more than one.


  3. The Subject has the List observers, but the Observer will have the Subject.


  4. Any change in the Subject will be notified to all the observers that the Subject stores in the form of a list.


  5. We can have the Subject as interface too. All depends on way we implement the above points.



enter image description here






share|improve this answer





















  • Thanks, I guess you are right. Implementation can vary as long as all the points holds true.
    – Syed Ahmed Jamil
    Nov 10 at 14:15










  • you are welcome buddy :) Glad could help.
    – janardhan sharma
    Nov 10 at 14:19













up vote
4
down vote



accepted







up vote
4
down vote



accepted






Observer D P is a simple.




  1. The Subject is the entity that the Observer watches.


  2. The Subject is single entity and the Observers can be more than one.


  3. The Subject has the List observers, but the Observer will have the Subject.


  4. Any change in the Subject will be notified to all the observers that the Subject stores in the form of a list.


  5. We can have the Subject as interface too. All depends on way we implement the above points.



enter image description here






share|improve this answer












Observer D P is a simple.




  1. The Subject is the entity that the Observer watches.


  2. The Subject is single entity and the Observers can be more than one.


  3. The Subject has the List observers, but the Observer will have the Subject.


  4. Any change in the Subject will be notified to all the observers that the Subject stores in the form of a list.


  5. We can have the Subject as interface too. All depends on way we implement the above points.



enter image description here







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 10 at 14:01









janardhan sharma

2406




2406












  • Thanks, I guess you are right. Implementation can vary as long as all the points holds true.
    – Syed Ahmed Jamil
    Nov 10 at 14:15










  • you are welcome buddy :) Glad could help.
    – janardhan sharma
    Nov 10 at 14:19


















  • Thanks, I guess you are right. Implementation can vary as long as all the points holds true.
    – Syed Ahmed Jamil
    Nov 10 at 14:15










  • you are welcome buddy :) Glad could help.
    – janardhan sharma
    Nov 10 at 14:19
















Thanks, I guess you are right. Implementation can vary as long as all the points holds true.
– Syed Ahmed Jamil
Nov 10 at 14:15




Thanks, I guess you are right. Implementation can vary as long as all the points holds true.
– Syed Ahmed Jamil
Nov 10 at 14:15












you are welcome buddy :) Glad could help.
– janardhan sharma
Nov 10 at 14:19




you are welcome buddy :) Glad could help.
– janardhan sharma
Nov 10 at 14:19












up vote
5
down vote













If Subject was an interface, then every class that implements Subject must re-implement all the registerObserver, unregisterObserver, and notify methods which are very standard.



You may say that you will put those methods into a helper class so that every derived Subject can just delegate the tasks to this helper. But after all, you have to duplicate the delegation code for all derived Subject classes. Althought the delegation code is short and straight-forward, that duplication is still frustrating.



You can find that argument near the end of this very interesting article of Uncle Bob: http://blog.cleancoder.com/uncle-bob/2015/01/08/InterfaceConsideredHarmful.html






share|improve this answer























  • Thanks that was a nice and funny read answered a lot of other frustrating questions
    – Syed Ahmed Jamil
    Nov 11 at 19:01















up vote
5
down vote













If Subject was an interface, then every class that implements Subject must re-implement all the registerObserver, unregisterObserver, and notify methods which are very standard.



You may say that you will put those methods into a helper class so that every derived Subject can just delegate the tasks to this helper. But after all, you have to duplicate the delegation code for all derived Subject classes. Althought the delegation code is short and straight-forward, that duplication is still frustrating.



You can find that argument near the end of this very interesting article of Uncle Bob: http://blog.cleancoder.com/uncle-bob/2015/01/08/InterfaceConsideredHarmful.html






share|improve this answer























  • Thanks that was a nice and funny read answered a lot of other frustrating questions
    – Syed Ahmed Jamil
    Nov 11 at 19:01













up vote
5
down vote










up vote
5
down vote









If Subject was an interface, then every class that implements Subject must re-implement all the registerObserver, unregisterObserver, and notify methods which are very standard.



You may say that you will put those methods into a helper class so that every derived Subject can just delegate the tasks to this helper. But after all, you have to duplicate the delegation code for all derived Subject classes. Althought the delegation code is short and straight-forward, that duplication is still frustrating.



You can find that argument near the end of this very interesting article of Uncle Bob: http://blog.cleancoder.com/uncle-bob/2015/01/08/InterfaceConsideredHarmful.html






share|improve this answer














If Subject was an interface, then every class that implements Subject must re-implement all the registerObserver, unregisterObserver, and notify methods which are very standard.



You may say that you will put those methods into a helper class so that every derived Subject can just delegate the tasks to this helper. But after all, you have to duplicate the delegation code for all derived Subject classes. Althought the delegation code is short and straight-forward, that duplication is still frustrating.



You can find that argument near the end of this very interesting article of Uncle Bob: http://blog.cleancoder.com/uncle-bob/2015/01/08/InterfaceConsideredHarmful.html







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 11 at 15:37

























answered Nov 10 at 16:09









Nghia Bui

1,189811




1,189811












  • Thanks that was a nice and funny read answered a lot of other frustrating questions
    – Syed Ahmed Jamil
    Nov 11 at 19:01


















  • Thanks that was a nice and funny read answered a lot of other frustrating questions
    – Syed Ahmed Jamil
    Nov 11 at 19:01
















Thanks that was a nice and funny read answered a lot of other frustrating questions
– Syed Ahmed Jamil
Nov 11 at 19:01




Thanks that was a nice and funny read answered a lot of other frustrating questions
– Syed Ahmed Jamil
Nov 11 at 19:01


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239652%2fsubject-of-observer-design-pattern-an-interface-or-a-super-class%23new-answer', 'question_page');
}
);

Post as a guest




















































































Popular posts from this blog

Full-time equivalent

Bicuculline

さくらももこ