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

Design and Architecture

 
AnswerRe: MVC without EF... Pin
Eddy Vluggen2-Jul-14 8:52
professionalEddy Vluggen2-Jul-14 8:52 
GeneralRe: MVC without EF... Pin
l a u r e n2-Jul-14 8:54
l a u r e n2-Jul-14 8:54 
QuestionPro and contra of "out of the box" solutions and frameworks Pin
McCormick9-Jun-14 4:26
McCormick9-Jun-14 4:26 
AnswerRe: Pro and contra of "out of the box" solutions and frameworks Pin
Eddy Vluggen9-Jun-14 4:32
professionalEddy Vluggen9-Jun-14 4:32 
GeneralRe: Pro and contra of "out of the box" solutions and frameworks Pin
Bastien Vandamme19-Jun-14 7:29
Bastien Vandamme19-Jun-14 7:29 
GeneralRe: Pro and contra of "out of the box" solutions and frameworks Pin
Eddy Vluggen21-Jun-14 8:17
professionalEddy Vluggen21-Jun-14 8:17 
AnswerRe: Pro and contra of "out of the box" solutions and frameworks Pin
Bastien Vandamme19-Jun-14 7:26
Bastien Vandamme19-Jun-14 7:26 
Generaln choose k: an exercise in design patterns Pin
BITjunkie5-Jun-14 17:25
BITjunkie5-Jun-14 17:25 
Hey guys, thanks for checking my post out. I'm writing this in hopes of getting some general feedback. Particularly, on my use of the design pattern and the abstractions I came up with.

I've been coding on-and-off for sometime now, but I never thought about design patterns until recently. I'm realizing how much I've missed out on Smile | :) ! But, anyway, I came across the decorator pattern in Head First Design Patterns and it got me thinking about a problem I couldn't solve a few years back...

It happened that I needed to enumerate all the different ways to choose k things from n things. The formula from discrete math tells you the total number of different ways to choose, but I needed to know what they were. I came up with a solution easily enough, but it was not acceptable. My solution (listed below) printed out all the different ways to choose 3 things from 6 things.
Java
for(int item1 = 0; item1 < 6; ++item1){
    for(int item2 = item1+1; item2 < 6; ++item2){
        for(int item3 = item2+1; item3 < 6; ++item3){
            System.out.println(item1 + " " + item2 + " " + item3);
        }
    }
}

Hopefully, it's obvious why it sucked! I could not vary, at run-time, the number of items I was choosing Cry | :(( . I could only vary the total number of things to choose from. Choosing an additional item required hard-coding another nested loop. So, I caved in and just restricted the user to a range and coded for every case Sigh | :sigh: .

It was when I was learning the decorator pattern that it hit me. They kept talking about how decorators 'wrap' and 'contain' things and how they can be built dynamically. The figure[^] they used to illustrate the concept screamed "NESTED FOR-LOOPS" at me. I HAD to try and apply this design pattern to my problem. It didn't matter if it did not work or if there was a better solution; I'd count it as practice.

I'm going to assume you are familiar with the Decorator Pattern[^], but I provided the link if not. So, basically, my abstract component is ItemSet and my only concrete component is ChooseItem. The abstract decorator is AdditionalItems and the concrete decorator is ChooseAdditionalItem. Hopefully, the way I named them makes it easy to picture how they work together. I have to say, IMO its pretty nice how effortless the solution looks in the main function. I've written a sample below.
Java
int setSize = 6;
int numberOfItemsToChoose = 3;

ItemSet itemSet = new ChooseItem(setSize);

for(int i=0; i < numberOfItemsToChoose-1; ++i)
    itemSet = new ChooseAdditionalItem(itemSet);

Queue<String> waysToChoose = itemSet.chooseItems();

for(String aWayToChoose : waysToChoose)
    System.out.println(aWayToChoose);

I promise the rest of the code is very short and human-readable, but I'd really, rather not post all the code here. Instead I'm providing a link[^] to it.

So, if you took a look at the code - thank you if you did! - you might have seen that this new solution is recursive. Meaning that all the different ways to choose are held in memory before they actually get printed out, whereas in the first one they were printed out immediately.

Any kind of feedback is appreciated. If you know of the best solution for this let me know or if you see a non-recursive solution, let me know too. Also, I am unemployed! So, help with that too would be amazing!

modified 5-Jun-14 23:48pm.

QuestionStandard protocol for inter-processor communication? Pin
arnold_w16-May-14 11:17
arnold_w16-May-14 11:17 
JokeRe: Standard protocol for inter-processor communication? Pin
OgRain8-Jun-14 23:00
OgRain8-Jun-14 23:00 
Questionnumericals related to computer architecture Pin
nischalinn10-May-14 23:55
nischalinn10-May-14 23:55 
AnswerRe: numericals related to computer architecture Pin
Richard MacCutchan11-May-14 1:11
mveRichard MacCutchan11-May-14 1:11 
QuestionBank System [?] Pin
sebasuraa8-May-14 6:31
sebasuraa8-May-14 6:31 
AnswerRe: Bank System [?] Pin
José Amílcar Casimiro8-May-14 6:48
José Amílcar Casimiro8-May-14 6:48 
GeneralRe: Bank System [?] Pin
sebasuraa8-May-14 6:49
sebasuraa8-May-14 6:49 
GeneralRe: Bank System [?] Pin
José Amílcar Casimiro8-May-14 7:03
José Amílcar Casimiro8-May-14 7:03 
AnswerRe: Bank System [?] Pin
jschell9-May-14 10:53
jschell9-May-14 10:53 
QuestionArchitecture for SharePoint 2013 Portal Pin
Maher Elsayed29-Apr-14 4:03
Maher Elsayed29-Apr-14 4:03 
QuestionIs 386 still supported? Pin
pixcraft18-Apr-14 1:10
pixcraft18-Apr-14 1:10 
GeneralRe: Is 386 still supported? Pin
harold aptroot18-Apr-14 2:39
harold aptroot18-Apr-14 2:39 
AnswerRe: Is 386 still supported? Pin
jschell2-May-14 10:08
jschell2-May-14 10:08 
QuestionA better way to do it? Pin
Cee Ann15-Apr-14 17:38
Cee Ann15-Apr-14 17:38 
AnswerRe: A better way to do it? Pin
Peter Leow15-Apr-14 18:03
professionalPeter Leow15-Apr-14 18:03 
GeneralRe: A better way to do it? Pin
Cee Ann15-Apr-14 20:32
Cee Ann15-Apr-14 20:32 
AnswerRe: A better way to do it? Pin
Mycroft Holmes15-Apr-14 20:16
professionalMycroft Holmes15-Apr-14 20:16 

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.