Can decorator pattern be replaced by a behavioral pattern to address a problem? The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceDoes functional programming replace GoF design patterns?How do the Proxy, Decorator, Adapter, and Bridge Patterns differ?Naming Classes - How to avoid calling everything a “<WhatEver>Manager”?Question about decorator pattern and the abstract decorator class?When and How Strategy pattern can be applied instead of decorator pattern?Decorator Pattern - Multiple wrappers or quantity property?Effectively using the Decorator patternIs this a good instance for the Decorator design pattern?Decorator design pattern vs. inheritance?Using Lists Instead of Decorator Pattern?
Take groceries in checked luggage
Can the prologue be the backstory of your main character?
Does Parliament need to approve the new Brexit delay to 31 October 2019?
What is special about square numbers here?
Is there a writing software that you can sort scenes like slides in PowerPoint?
Scientific Reports - Significant Figures
Road tyres vs "Street" tyres for charity ride on MTB Tandem
How do I add random spotting to the same face in cycles?
Are spiders unable to hurt humans, especially very small spiders?
Who or what is the being for whom Being is a question for Heidegger?
How to remove this toilet supply line that seems to have no nut?
Make it rain characters
Why does the Event Horizon Telescope (EHT) not include telescopes from Africa, Asia or Australia?
How can I define good in a religion that claims no moral authority?
Is above average number of years spent on PhD considered a red flag in future academia or industry positions?
Relations between two reciprocal partial derivatives?
Typeface like Times New Roman but with "tied" percent sign
Windows 10: How to Lock (not sleep) laptop on lid close?
"... to apply for a visa" or "... and applied for a visa"?
How to politely respond to generic emails requesting a PhD/job in my lab? Without wasting too much time
How can I protect witches in combat who wear limited clothing?
How to delete random line from file using Unix command?
Why did all the guest students take carriages to the Yule Ball?
How should I replace vector<uint8_t>::const_iterator in an API?
Can decorator pattern be replaced by a behavioral pattern to address a problem?
The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceDoes functional programming replace GoF design patterns?How do the Proxy, Decorator, Adapter, and Bridge Patterns differ?Naming Classes - How to avoid calling everything a “<WhatEver>Manager”?Question about decorator pattern and the abstract decorator class?When and How Strategy pattern can be applied instead of decorator pattern?Decorator Pattern - Multiple wrappers or quantity property?Effectively using the Decorator patternIs this a good instance for the Decorator design pattern?Decorator design pattern vs. inheritance?Using Lists Instead of Decorator Pattern?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have read and seen many examples describing why decorator is a structural pattern. And how it's composing objects to add new functionalities.
While Visitor pattern helps with adding new functions to an object. And strategy pattern is to swap algorithm at run time.
I still can't wrap my head around the concept of why decorator pattern is a structural and not a behavioral pattern.
Can someone exemplify these patterns with few real world programming examples? The pizza and flying duck examples makes me think that I understand, but in a while I end up with - what did I just read.
Would be really helpful to take a real system design, spilt into smaller problems and apply all these design patterns.
EDIT: Took the following use case to apply and understand different design patterns. Please share your thoughts on this example.
An voice interactive system for Museum where kids can ask anything and get information about it and book tickets for any shows.
Eg: kid asks what is solar system, and then drills down with questions about planets. Then book tickets for a planetarium show.
Here are the technical use cases where design patterns can be applied. Please help choose the right design patterns for each case:
1) Listen to kid's questions and parse data from it.
2) Identify if kid is asking information or requesting direction or want to book a ticket and so on...
3) Based on the kid intent, respond with an answer or collect more info to book ticket or schedule a group tour.
4) Manage conversations and context data.
5) Call API to get an answer or book a tour.
Would like to apply design patterns so that the system can follow SOLID principles.
Design requirement for each of the above use case:
1) With out modifying existing code the system should accept new input methods (touch, voice, keyboard, mouse) by following OCP. Also accept new sensor inputs like facial reaction while kids ask question.
2) The system should be extensible to support new user intents.
3) Some questions have straight forward answers and some cases need follow-up questions to get more details from kids (book tour). Here every conversation does similar things (listens to the kid, system does something, respond to the kid with follow up or an answer). Can decorator design pattern be used here to compose objects like parent object (to get what the kid want to do) and child objects (to get follow-up details to book tour)
4) Should be able to reuse the same design to manage any flow of back and forth questions and manage the context data.
5) loosely couple the APIs, swapping APIs as needed, support API from different providers to book tour, answer questions etc. (Strategy pattern ?). If it involves multiple API competing for book the tour and the system chooses one API, what would be a good pattern to use.
The system should be extensible to support new use cases like 'ask for help from a museum employee' or 'buy a coffee from food court' or 'sign up for volunteering'.
Not sure if this forum supports this kind of discussion. But I couldn't find a better forum to take this discussion.
java design-patterns architecture
add a comment |
I have read and seen many examples describing why decorator is a structural pattern. And how it's composing objects to add new functionalities.
While Visitor pattern helps with adding new functions to an object. And strategy pattern is to swap algorithm at run time.
I still can't wrap my head around the concept of why decorator pattern is a structural and not a behavioral pattern.
Can someone exemplify these patterns with few real world programming examples? The pizza and flying duck examples makes me think that I understand, but in a while I end up with - what did I just read.
Would be really helpful to take a real system design, spilt into smaller problems and apply all these design patterns.
EDIT: Took the following use case to apply and understand different design patterns. Please share your thoughts on this example.
An voice interactive system for Museum where kids can ask anything and get information about it and book tickets for any shows.
Eg: kid asks what is solar system, and then drills down with questions about planets. Then book tickets for a planetarium show.
Here are the technical use cases where design patterns can be applied. Please help choose the right design patterns for each case:
1) Listen to kid's questions and parse data from it.
2) Identify if kid is asking information or requesting direction or want to book a ticket and so on...
3) Based on the kid intent, respond with an answer or collect more info to book ticket or schedule a group tour.
4) Manage conversations and context data.
5) Call API to get an answer or book a tour.
Would like to apply design patterns so that the system can follow SOLID principles.
Design requirement for each of the above use case:
1) With out modifying existing code the system should accept new input methods (touch, voice, keyboard, mouse) by following OCP. Also accept new sensor inputs like facial reaction while kids ask question.
2) The system should be extensible to support new user intents.
3) Some questions have straight forward answers and some cases need follow-up questions to get more details from kids (book tour). Here every conversation does similar things (listens to the kid, system does something, respond to the kid with follow up or an answer). Can decorator design pattern be used here to compose objects like parent object (to get what the kid want to do) and child objects (to get follow-up details to book tour)
4) Should be able to reuse the same design to manage any flow of back and forth questions and manage the context data.
5) loosely couple the APIs, swapping APIs as needed, support API from different providers to book tour, answer questions etc. (Strategy pattern ?). If it involves multiple API competing for book the tour and the system chooses one API, what would be a good pattern to use.
The system should be extensible to support new use cases like 'ask for help from a museum employee' or 'buy a coffee from food court' or 'sign up for volunteering'.
Not sure if this forum supports this kind of discussion. But I couldn't find a better forum to take this discussion.
java design-patterns architecture
add a comment |
I have read and seen many examples describing why decorator is a structural pattern. And how it's composing objects to add new functionalities.
While Visitor pattern helps with adding new functions to an object. And strategy pattern is to swap algorithm at run time.
I still can't wrap my head around the concept of why decorator pattern is a structural and not a behavioral pattern.
Can someone exemplify these patterns with few real world programming examples? The pizza and flying duck examples makes me think that I understand, but in a while I end up with - what did I just read.
Would be really helpful to take a real system design, spilt into smaller problems and apply all these design patterns.
EDIT: Took the following use case to apply and understand different design patterns. Please share your thoughts on this example.
An voice interactive system for Museum where kids can ask anything and get information about it and book tickets for any shows.
Eg: kid asks what is solar system, and then drills down with questions about planets. Then book tickets for a planetarium show.
Here are the technical use cases where design patterns can be applied. Please help choose the right design patterns for each case:
1) Listen to kid's questions and parse data from it.
2) Identify if kid is asking information or requesting direction or want to book a ticket and so on...
3) Based on the kid intent, respond with an answer or collect more info to book ticket or schedule a group tour.
4) Manage conversations and context data.
5) Call API to get an answer or book a tour.
Would like to apply design patterns so that the system can follow SOLID principles.
Design requirement for each of the above use case:
1) With out modifying existing code the system should accept new input methods (touch, voice, keyboard, mouse) by following OCP. Also accept new sensor inputs like facial reaction while kids ask question.
2) The system should be extensible to support new user intents.
3) Some questions have straight forward answers and some cases need follow-up questions to get more details from kids (book tour). Here every conversation does similar things (listens to the kid, system does something, respond to the kid with follow up or an answer). Can decorator design pattern be used here to compose objects like parent object (to get what the kid want to do) and child objects (to get follow-up details to book tour)
4) Should be able to reuse the same design to manage any flow of back and forth questions and manage the context data.
5) loosely couple the APIs, swapping APIs as needed, support API from different providers to book tour, answer questions etc. (Strategy pattern ?). If it involves multiple API competing for book the tour and the system chooses one API, what would be a good pattern to use.
The system should be extensible to support new use cases like 'ask for help from a museum employee' or 'buy a coffee from food court' or 'sign up for volunteering'.
Not sure if this forum supports this kind of discussion. But I couldn't find a better forum to take this discussion.
java design-patterns architecture
I have read and seen many examples describing why decorator is a structural pattern. And how it's composing objects to add new functionalities.
While Visitor pattern helps with adding new functions to an object. And strategy pattern is to swap algorithm at run time.
I still can't wrap my head around the concept of why decorator pattern is a structural and not a behavioral pattern.
Can someone exemplify these patterns with few real world programming examples? The pizza and flying duck examples makes me think that I understand, but in a while I end up with - what did I just read.
Would be really helpful to take a real system design, spilt into smaller problems and apply all these design patterns.
EDIT: Took the following use case to apply and understand different design patterns. Please share your thoughts on this example.
An voice interactive system for Museum where kids can ask anything and get information about it and book tickets for any shows.
Eg: kid asks what is solar system, and then drills down with questions about planets. Then book tickets for a planetarium show.
Here are the technical use cases where design patterns can be applied. Please help choose the right design patterns for each case:
1) Listen to kid's questions and parse data from it.
2) Identify if kid is asking information or requesting direction or want to book a ticket and so on...
3) Based on the kid intent, respond with an answer or collect more info to book ticket or schedule a group tour.
4) Manage conversations and context data.
5) Call API to get an answer or book a tour.
Would like to apply design patterns so that the system can follow SOLID principles.
Design requirement for each of the above use case:
1) With out modifying existing code the system should accept new input methods (touch, voice, keyboard, mouse) by following OCP. Also accept new sensor inputs like facial reaction while kids ask question.
2) The system should be extensible to support new user intents.
3) Some questions have straight forward answers and some cases need follow-up questions to get more details from kids (book tour). Here every conversation does similar things (listens to the kid, system does something, respond to the kid with follow up or an answer). Can decorator design pattern be used here to compose objects like parent object (to get what the kid want to do) and child objects (to get follow-up details to book tour)
4) Should be able to reuse the same design to manage any flow of back and forth questions and manage the context data.
5) loosely couple the APIs, swapping APIs as needed, support API from different providers to book tour, answer questions etc. (Strategy pattern ?). If it involves multiple API competing for book the tour and the system chooses one API, what would be a good pattern to use.
The system should be extensible to support new use cases like 'ask for help from a museum employee' or 'buy a coffee from food court' or 'sign up for volunteering'.
Not sure if this forum supports this kind of discussion. But I couldn't find a better forum to take this discussion.
java design-patterns architecture
java design-patterns architecture
edited Mar 24 at 17:05
user2175981
asked Mar 22 at 6:40
user2175981user2175981
112
112
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Behavioral design patterns are concerned with the interaction and responsibility of objects. In these design patterns, the interaction between the objects should enable them to easily talk to each other and still be loosely coupled. Visitor in your case lets you define a new operation over the object structure without changing the classes of the elements on which it operates.
Structural design patterns on the other hand are concerned with how classes and objects can be composed to form larger structures. It is the structure that is flexible.
interface Executable
void execute();
class DeleteUser implements Executable
@Override
public void execute()
// delete
class LoggingExecutable implements Executable
private final Executable executable;
@Override
public void execute()
// log before
executable.execute();
// log after
class TransactionalExecutable implements Executable
private final Executable executable;
@Override
public void execute()
// open transaction
try
executable.execute();
catch (FooException e)
// rollback
finally
// close transaction
Here is a hypothetical composite structure with use of decorators. As you can see it is the structure that is flexible. I can construct Executable
that is both logging and transactional, but I am free to have it just logging for example or decorated with something completely different.
new LoggingExecutable(
new TransactionalExecutable(
new DeleteUser()));
new LoggingExecutable(
new DeleteUser());
Thanks Januson. Edited my question with specific examples.
– user2175981
Mar 24 at 18:42
add a comment |
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',
autoActivateHeartbeat: false,
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
);
);
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55294159%2fcan-decorator-pattern-be-replaced-by-a-behavioral-pattern-to-address-a-problem%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Behavioral design patterns are concerned with the interaction and responsibility of objects. In these design patterns, the interaction between the objects should enable them to easily talk to each other and still be loosely coupled. Visitor in your case lets you define a new operation over the object structure without changing the classes of the elements on which it operates.
Structural design patterns on the other hand are concerned with how classes and objects can be composed to form larger structures. It is the structure that is flexible.
interface Executable
void execute();
class DeleteUser implements Executable
@Override
public void execute()
// delete
class LoggingExecutable implements Executable
private final Executable executable;
@Override
public void execute()
// log before
executable.execute();
// log after
class TransactionalExecutable implements Executable
private final Executable executable;
@Override
public void execute()
// open transaction
try
executable.execute();
catch (FooException e)
// rollback
finally
// close transaction
Here is a hypothetical composite structure with use of decorators. As you can see it is the structure that is flexible. I can construct Executable
that is both logging and transactional, but I am free to have it just logging for example or decorated with something completely different.
new LoggingExecutable(
new TransactionalExecutable(
new DeleteUser()));
new LoggingExecutable(
new DeleteUser());
Thanks Januson. Edited my question with specific examples.
– user2175981
Mar 24 at 18:42
add a comment |
Behavioral design patterns are concerned with the interaction and responsibility of objects. In these design patterns, the interaction between the objects should enable them to easily talk to each other and still be loosely coupled. Visitor in your case lets you define a new operation over the object structure without changing the classes of the elements on which it operates.
Structural design patterns on the other hand are concerned with how classes and objects can be composed to form larger structures. It is the structure that is flexible.
interface Executable
void execute();
class DeleteUser implements Executable
@Override
public void execute()
// delete
class LoggingExecutable implements Executable
private final Executable executable;
@Override
public void execute()
// log before
executable.execute();
// log after
class TransactionalExecutable implements Executable
private final Executable executable;
@Override
public void execute()
// open transaction
try
executable.execute();
catch (FooException e)
// rollback
finally
// close transaction
Here is a hypothetical composite structure with use of decorators. As you can see it is the structure that is flexible. I can construct Executable
that is both logging and transactional, but I am free to have it just logging for example or decorated with something completely different.
new LoggingExecutable(
new TransactionalExecutable(
new DeleteUser()));
new LoggingExecutable(
new DeleteUser());
Thanks Januson. Edited my question with specific examples.
– user2175981
Mar 24 at 18:42
add a comment |
Behavioral design patterns are concerned with the interaction and responsibility of objects. In these design patterns, the interaction between the objects should enable them to easily talk to each other and still be loosely coupled. Visitor in your case lets you define a new operation over the object structure without changing the classes of the elements on which it operates.
Structural design patterns on the other hand are concerned with how classes and objects can be composed to form larger structures. It is the structure that is flexible.
interface Executable
void execute();
class DeleteUser implements Executable
@Override
public void execute()
// delete
class LoggingExecutable implements Executable
private final Executable executable;
@Override
public void execute()
// log before
executable.execute();
// log after
class TransactionalExecutable implements Executable
private final Executable executable;
@Override
public void execute()
// open transaction
try
executable.execute();
catch (FooException e)
// rollback
finally
// close transaction
Here is a hypothetical composite structure with use of decorators. As you can see it is the structure that is flexible. I can construct Executable
that is both logging and transactional, but I am free to have it just logging for example or decorated with something completely different.
new LoggingExecutable(
new TransactionalExecutable(
new DeleteUser()));
new LoggingExecutable(
new DeleteUser());
Behavioral design patterns are concerned with the interaction and responsibility of objects. In these design patterns, the interaction between the objects should enable them to easily talk to each other and still be loosely coupled. Visitor in your case lets you define a new operation over the object structure without changing the classes of the elements on which it operates.
Structural design patterns on the other hand are concerned with how classes and objects can be composed to form larger structures. It is the structure that is flexible.
interface Executable
void execute();
class DeleteUser implements Executable
@Override
public void execute()
// delete
class LoggingExecutable implements Executable
private final Executable executable;
@Override
public void execute()
// log before
executable.execute();
// log after
class TransactionalExecutable implements Executable
private final Executable executable;
@Override
public void execute()
// open transaction
try
executable.execute();
catch (FooException e)
// rollback
finally
// close transaction
Here is a hypothetical composite structure with use of decorators. As you can see it is the structure that is flexible. I can construct Executable
that is both logging and transactional, but I am free to have it just logging for example or decorated with something completely different.
new LoggingExecutable(
new TransactionalExecutable(
new DeleteUser()));
new LoggingExecutable(
new DeleteUser());
answered Mar 22 at 7:39
JanusonJanuson
2,2831429
2,2831429
Thanks Januson. Edited my question with specific examples.
– user2175981
Mar 24 at 18:42
add a comment |
Thanks Januson. Edited my question with specific examples.
– user2175981
Mar 24 at 18:42
Thanks Januson. Edited my question with specific examples.
– user2175981
Mar 24 at 18:42
Thanks Januson. Edited my question with specific examples.
– user2175981
Mar 24 at 18:42
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55294159%2fcan-decorator-pattern-be-replaced-by-a-behavioral-pattern-to-address-a-problem%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown