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
CODE (SUBJECT)
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
add a comment |
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
CODE (SUBJECT)
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
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
add a comment |
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
CODE (SUBJECT)
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
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
CODE (SUBJECT)
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
java oop design-patterns uml
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
up vote
4
down vote
accepted
Observer D P is a simple.
The Subject is the entity that the Observer watches.
The Subject is single entity and the Observers can be more than one.
The Subject has the List observers, but the Observer will have the Subject.
Any change in the Subject will be notified to all the observers that the Subject stores in the form of a list.
We can have the Subject as interface too. All depends on way we implement the above points.
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
add a comment |
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
Thanks that was a nice and funny read answered a lot of other frustrating questions
– Syed Ahmed Jamil
Nov 11 at 19:01
add a comment |
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.
The Subject is the entity that the Observer watches.
The Subject is single entity and the Observers can be more than one.
The Subject has the List observers, but the Observer will have the Subject.
Any change in the Subject will be notified to all the observers that the Subject stores in the form of a list.
We can have the Subject as interface too. All depends on way we implement the above points.
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
add a comment |
up vote
4
down vote
accepted
Observer D P is a simple.
The Subject is the entity that the Observer watches.
The Subject is single entity and the Observers can be more than one.
The Subject has the List observers, but the Observer will have the Subject.
Any change in the Subject will be notified to all the observers that the Subject stores in the form of a list.
We can have the Subject as interface too. All depends on way we implement the above points.
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
add a comment |
up vote
4
down vote
accepted
up vote
4
down vote
accepted
Observer D P is a simple.
The Subject is the entity that the Observer watches.
The Subject is single entity and the Observers can be more than one.
The Subject has the List observers, but the Observer will have the Subject.
Any change in the Subject will be notified to all the observers that the Subject stores in the form of a list.
We can have the Subject as interface too. All depends on way we implement the above points.
Observer D P is a simple.
The Subject is the entity that the Observer watches.
The Subject is single entity and the Observers can be more than one.
The Subject has the List observers, but the Observer will have the Subject.
Any change in the Subject will be notified to all the observers that the Subject stores in the form of a list.
We can have the Subject as interface too. All depends on way we implement the above points.
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
add a comment |
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
add a comment |
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
Thanks that was a nice and funny read answered a lot of other frustrating questions
– Syed Ahmed Jamil
Nov 11 at 19:01
add a comment |
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
Thanks that was a nice and funny read answered a lot of other frustrating questions
– Syed Ahmed Jamil
Nov 11 at 19:01
add a comment |
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
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
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
add a comment |
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
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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