• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 21:06
CET 03:06
KST 11:06
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10
Community News
Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2BGE Stara Zagora 2026 announced15[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3RSL Season 3: RO16 results & RO8 bracket13
StarCraft 2
General
Chinese SC2 server to reopen; live all-star event in Hangzhou Maestros of the Game: Live Finals Preview (RO4) BGE Stara Zagora 2026 announced Weekly Cups (Nov 24-30): MaxPax, Clem, herO win SC2 Proleague Discontinued; SKT, KT, SGK, CJ disband
Tourneys
RSL Offline FInals Sea Duckling Open (Global, Bronze-Diamond) $5,000+ WardiTV 2025 Championship Constellation Cup - Main Event - Stellar Fest RSL Revival: Season 3
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress Mutation # 500 Fright night Mutation # 499 Chilling Adaptation
Brood War
General
BW General Discussion Which season is the best in ASL? Data analysis on 70 million replays BGH Auto Balance -> http://bghmmr.eu/ [ASL20] Ask the mapmakers — Drop your questions
Tourneys
[BSL21] RO16 Group D - Sunday 21:00 CET [BSL21] RO16 Group A - Saturday 21:00 CET [Megathread] Daily Proleagues [BSL21] RO16 Group B - Sunday 21:00 CET
Strategy
Current Meta Game Theory for Starcraft How to stay on top of macro? PvZ map balance
Other Games
General Games
ZeroSpace Megathread Stormgate/Frost Giant Megathread Nintendo Switch Thread The Perfect Game Path of Exile
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Mafia Game Mode Feedback/Ideas TL Mafia Community Thread
Community
General
Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread US Politics Mega-thread The Big Programming Thread Artificial Intelligence Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Where to ask questions and add stream? The Automated Ban List
Blogs
James Bond movies ranking - pa…
Topin
Esports Earnings: Bigger Pri…
TrAiDoS
Thanks for the RSL
Hildegard
Saturation point
Uldridge
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1356 users

The Big Programming Thread - Page 485

Forum Index > General Forum
Post a Reply
Prev 1 483 484 485 486 487 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
sluggaslamoo
Profile Blog Joined November 2009
Australia4494 Posts
Last Edited: 2014-05-28 03:29:28
May 28 2014 03:26 GMT
#9681
On May 28 2014 00:59 supereddie wrote:
Show nested quote +
On May 27 2014 16:29 Blisse wrote:
can't really post code (not allowed) so i'll try to explain it

basically trying to emulate the dispatching in a switch rather than using a long if statement. the input isn't user defined, but selected from a known dictionary, and the input is runtime dependent.

imagine in a commandline program you could type PULL to call a pullFunction and PUSH to call a pushFunction, while passing in arbitrary container objects. the function could then take the container object and because you called that exact function, cast the contents inside the container object to the proper type. so pullFunction(Container container) will have a method like var pullObject = container.Contents as pullObject. it then passed this object to another library and returns a variable container object with the results of that library call and the description of what the container contains.

i simplified things a bit, there is a lot more logic inbetween and 10-20 different inputs that should be handled. i could always just write an if-statement too, i don't have a specific reason between the two except that this runs faster and the mapping between "PULL" and "pullFunction" is enforced a bit more strictly and visually.

So, what I get from this:
1. The functions that are available to the users are known to your program
2. Each function has one argument
3. The return value of each function is known and can be generalized (that is, made the same for all functions)

Design an interface, create classes for each function that implement said interface, and create a factory class that creates the function classes.

For example:

internal interface IFunction
{
string Execute(object parameter);
}

internal sealed class PullFunction : IFunction
{
public string Execute(object parameter)
{
MyCustomClassForThisFunction c = parameter as MyCustomClassForThisFunction;
if(c == null) return string.Empty;

// do stuff
// return result
}
}

internal interface IFunctionFactory
{
IFunction Create(string functionName);
}

internal sealed class FunctionFactory : IFunctionFactory
{
public IFunction Create(string functionName)
{
switch(functionName.ToUpper())
{
case "PULL":
return new PullFunction();
default:
throw new NotImlementedException();
}
}
}

// In your command handling code, find a way to inject the factory via constructor injection
private readonly IFunctionFactory functionFactory;
return this.functionFactory.Create("pull").Execute(arbitraryContainerObject);


Now you can get cutesy and still have a dictionary mapping a function name to a type in the Factory, without altering the rest of your code:

private readonly IDictionary<string, Type> functionMapping = new Dictionary<string, Type>
{
new KeyValuePair<string, Type>("PULL", typeof(PullFunction))
}

// In Create method
// be sure to check if the key exists etc.
return Activator.CreateInstance(this.functionMapping[functionName.ToUpper()]);


Sidenote: I've been making more factories lately and have become a fan


Be careful about being obsessed over design patterns. The factory pattern is not a appropriate fit for this problem, also the classic factory pattern is quite obtuse, have a look at how ODM's work, they use a much better implementation of the factory pattern.

You do not need a factory to create functions. Functions have their own logic, a factory is not smart enough to create the logic so all it is doing is creating an insertion in the dictionary, hardly useful. Factories are used to facilitate building complex stateful objects, such as instantiating models. You also have a switch statement, which makes the factory redundant. If you are going to use a case-by-case feature for your logic, then you may as well just remove the dictionary altogether.

What you need is reflection, this means you do not need a switch statement, you do not need a dictionary, and you can implement your logic as if it were a normal program.

If you want a good example of the factory pattern, have a look at factory_girl.

http://rubydoc.info/gems/factory_girl/1.3.3/frames
Come play Android Netrunner - http://www.teamliquid.net/forum/viewmessage.php?topic_id=409008
supereddie
Profile Joined March 2011
Netherlands151 Posts
May 28 2014 16:10 GMT
#9682
On May 28 2014 12:26 sluggaslamoo wrote:
Be careful about being obsessed over design patterns. The factory pattern is not a appropriate fit for this problem, also the classic factory pattern is quite obtuse, have a look at how ODM's work, they use a much better implementation of the factory pattern.

You do not need a factory to create functions. Functions have their own logic, a factory is not smart enough to create the logic so all it is doing is creating an insertion in the dictionary, hardly useful. Factories are used to facilitate building complex stateful objects, such as instantiating models. You also have a switch statement, which makes the factory redundant. If you are going to use a case-by-case feature for your logic, then you may as well just remove the dictionary altogether.

I only gave an example of how it could be done; I never said this was the only way. As always in programming, there are many ways to solve a problem. I just took one and gave some simplified sample code.

'Functions' do not exists, therefore you cannot create them. Everything is a member of some object. I merely moved the corresponding code to their own classes and gave it a common interface.

I think you misunderstand the sample I gave. It is about abstracting away instantiation of concrete types to the factory. The consumer then only uses the interface (as the consumer shouldn't care about the concrete implementation). This improves maintainability, testability, debugging and a lot more.

If you believe factories are only used to 'facilitate building complex stateful objects' and using a switch statement 'makes the factory redundant', you should read up about common OOP priciples, such as encaspulation and polymorphism.
On May 28 2014 12:26 sluggaslamoo wrote:
What you need is reflection, this means you do not need a switch statement, you do not need a dictionary, and you can implement your logic as if it were a normal program.

You don't need to use anything. Use whatever suits your purpose. In this case, I feel reflection is not the right tool. Simply because everything is already known. Therefore you can design your program better, to create a more maintainable, testable and predictable application.

On May 28 2014 12:26 sluggaslamoo wrote:
If you want a good example of the factory pattern, have a look at factory_girl.

http://rubydoc.info/gems/factory_girl/1.3.3/frames

That is just one of the many, many possible implementations of a factory pattern. In fact, it behaves more like an Inversion-Of-Control container than a factory. I see a lot of problems with that one page and it's implementation/usage.
Simply trying to create a unit test for a method that uses that 'factory' would be a pain.

Sidenote: I dislike static members as they can't be mocked for unit testing. Avoid static methods at any cost (but if there is a legitimate reason, go ahead).
"Do not try to make difficult things possible, but make simple things simple." - David Platt on Software Design
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
May 28 2014 16:37 GMT
#9683
If you use reflection to implement your factory that's fine. If you use reflection all over your code then that's awful. Reflection should always be tucked away into a vary narrow class. Your actual code should run on proper interfaces.

Also yay for disliking static.
If you have a good reason to disagree with the above, please tell me. Thank you.
Release
Profile Blog Joined October 2010
United States4397 Posts
Last Edited: 2014-05-28 18:29:54
May 28 2014 18:20 GMT
#9684
Multi-threaded sorting problem;

Here is a working multithreaded quicksort for ArrayLists of Generic <T extends Comparable<T>>. Tested on ArrayList<Integer>s
+ Show Spoiler +

public static <T extends Comparable<T>> void quicksortm(ArrayList<T> list, int from, int to) {
if (list.size() < 90000) {
quicksort(list, from, to);
return;
}
ArrayBlockingQueue<quicksortTask<T>> taskQueue = new ArrayBlockingQueue<quicksortTask<T>>((to - from)/9);
ArrayList<quicksortThread<T>> workers = new ArrayList<quicksortThread<T>>();
int numberProcessors = Runtime.getRuntime().availableProcessors();

for (int i = 0; i < 2 * numberProcessors; i++) {
workers.add(new quicksortThread<>(taskQueue));
}

try {
taskQueue.put(new quicksortTask<>(list, from, to));
} catch (InterruptedException e) {

}
for (quicksortThread<T> worker:workers) {
worker.start();
while (taskQueue.size() < 1) {

}
}
for (quicksortThread<T> worker:workers) {
while (worker.isAlive()) {
try {
worker.join();
}
catch (InterruptedException e) {

}
}
}
}

public static class quicksortThread<T extends Comparable<T>> extends Thread {
ArrayBlockingQueue<quicksortTask<T>> taskQueue;

public quicksortThread(ArrayBlockingQueue<quicksortTask<T>> taskQueue) {
this.taskQueue = taskQueue;
}

public void run() {
quicksortTask<T> task = null;

while (!taskQueue.isEmpty()) {
try {
task = taskQueue.take();
}
catch (InterruptedException e) {

}
quicksortTaskPair<T> qstp = task.run();
if (qstp == null) {
continue;
}
if (qstp.a() != null) {
try {
taskQueue.put(qstp.a());
} catch (InterruptedException e) {

}
}
if (qstp.b() != null) {
try {
taskQueue.put(qstp.b());
} catch (InterruptedException e) {

}
}
}
}
}

public static class quicksortTask<T extends Comparable<T>> {
ArrayList<T> list;
int from;
int to;

public quicksortTask(ArrayList<T> list, int from, int to) {
this.list = list;
this.from = from;
this.to = to;
}

public quicksortTaskPair<T> run() {
if (from >= to) {
return null;
}

if (to - from < 17) {
insertionSort(list, from, to);
return null;
}

T pivot;
T temp;

int pivotIndex = from + (int)((to - from + 1) * Math.random());
pivot = list.get(pivotIndex);
swap(list, pivotIndex, to);

int left = from;

for (int i = from ; i < to; i++) {
temp = list.get(i);

if (temp.compareTo(pivot) <= 0) {
swap(list, left, i);
left++;
}
}

swap(list, left, to);

return new quicksortTaskPair<T>(new quicksortTask<T>(list, from, left - 1), new quicksortTask<T>(list, left + 1, to));
}
}

public static class quicksortTaskPair<T extends Comparable<T>> {
quicksortTask<T> first;
quicksortTask<T> second;

public quicksortTaskPair(quicksortTask<T> first, quicksortTask<T> second) {
this.first = first;
this.second = second;
}

public quicksortTask<T> a() {
return first;
}

public quicksortTask<T> b() {
return second;
}
}

public static <T> void swap(ArrayList<T> list, int i, int j) {
T temp = list.get(i);
list.set(i, list.get(j));
list.set(j, temp);
}


but when I try to switch it to work on int[] arrays, it will hang before it finishes sorting the array. I am not sure why this is so. I only changed ArrayList<T> to int[] and T types to int types where applicable.

Some debugging shows that for sufficiently large lists, all threads will start, many quicksortTasks will execute, but at some point, no quicksortTasks will continue to execute, despite the fact that the taskQueue is not empty.
+ Show Spoiler +

public static void quicksortmu(int[] list, int from, int to) {
if (list.length < 90000) {
sort(list);
return;
}
ArrayBlockingQueue<quicksortTask> taskQueue = new ArrayBlockingQueue<quicksortTask>((to - from)/9);
ArrayList<quicksortThread> workers = new ArrayList<quicksortThread>();
int numberProcessors = Runtime.getRuntime().availableProcessors();

for (int i = 0; i < 2 * numberProcessors; i++) {
workers.add(new quicksortThread(taskQueue));
}

try {
taskQueue.put(new quicksortTask(list, from, to));
} catch (InterruptedException e) {

}
for (quicksortThread worker:workers) {
worker.start();
while (taskQueue.size() < 1) {

}
}
for (quicksortThread worker:workers) {
while (worker.isAlive()) {
try {
worker.join();
}
catch (InterruptedException e) {

}
}
}
}

public static class quicksortThread extends Thread {
ArrayBlockingQueue<quicksortTask> taskQueue;

public quicksortThread(ArrayBlockingQueue<quicksortTask> taskQueue) {
this.taskQueue = taskQueue;
}

public void run() {
quicksortTask task = null;

while (!taskQueue.isEmpty()) {
try {
task = taskQueue.take();
}
catch (InterruptedException e) {

}
quicksortTaskPair qstp = task.run();
if (qstp == null) {
continue;
}
if (qstp.a() != null) {
try {
taskQueue.put(qstp.a());
} catch (InterruptedException e) {

}
}
if (qstp.b() != null) {
try {
taskQueue.put(qstp.b());
} catch (InterruptedException e) {

}
}
}
}
}

public static class quicksortTask {
int[] list;
int from;
int to;

public quicksortTask(int[] list, int from, int to) {
this.list = list;
this.from = from;
this.to = to;
}

public quicksortTaskPair run() {
if (from >= to) {
return null;
}

int pivot;
int temp;

int pivotIndex = from + (int)((to - from + 1) * Math.random());
pivot = list[pivotIndex];
swap(list, pivotIndex, to);

int left = from;

for (int i = from ; i < to; i++) {
temp = list[i];

if (temp < pivot) {
swap(list, left, i);
left++;
}
}

swap(list, left, to);

return new quicksortTaskPair(new quicksortTask(list, from, left - 1), new quicksortTask(list, left + 1, to));
}
}

public static class quicksortTaskPair {
quicksortTask first;
quicksortTask second;

public quicksortTaskPair(quicksortTask first, quicksortTask second) {
this.first = first;
this.second = second;
}

public quicksortTask a() {
return first;
}

public quicksortTask b() {
return second;
}
}

public static void swap(int[] list, int i, int j) {
int temp = list[i];
list[i] = list[j];
list[j] = temp;
}
☺
phar
Profile Joined August 2011
United States1080 Posts
May 29 2014 01:32 GMT
#9685
Of potential interest to some people here (seem to recall someone doing datacenter efficiency modeling):

https://docs.google.com/a/google.com/viewer?url=www.google.com/about/datacenters/efficiency/internal/assets/machine-learning-applicationsfor-datacenter-optimization-finalv2.pdf
Who after all is today speaking about the destruction of the Armenians?
FFGenerations
Profile Blog Joined April 2011
7088 Posts
May 29 2014 02:51 GMT
#9686
I'm just throwing together the basis of converting my visual novel to OOP Flash AS3... If you're a Flash/OOP pro and have the time feel free to take a look and comment on this structure while I sleep....
+ Show Spoiler +


[image loading]


a) I have dialoguebox and textbox separate because i think i'll need them to act separately e.g. the dialoguebox doesn't close exactly the same time as the textbox will close.

b) In the diagram i am not showing button functionality e.g. clicking on dialoguebox will progress the text/scene, clicking on options button will store the choice and progress the scene... i'm not sure if i'm supposed to show these things in this diagram? the nature of Flash is confusing me i think, coz these are like inbuilt functions.....

how will i be doing these things? some scene attributes will be pre-set so i guess it will look like.....

displayScene(scene1)
scene1.displayCharacterLeft
scene1.displayCharacterRight
scene1.displayDialogueBox
scene1.displayDialogueText("Yuki: Hi, I'm Yuki")
scene1.displayDialogueText("Gendo: Hello Yuki")
scene1.displayOptionBox
scene1.displayOptions
eventListenerOnClick ->setOptionTrue, hideOptions, displayDialogueText("Nice choice")
endScene(scene1)
displayScene(scene2)

do i want to type out all my game dialogue in the main class rather than in a scene? (i think i do)

maybe someone can simplify the way i should think about this...

disclaimer: i would be doing some bloody flash youtube tutorials but my router broke in a storm and i can barely load youtube at 5k/s on mobile net



screenshot of the game (failed prototype version)
[image loading]



Cool BW Music Vid - youtube.com/watch?v=W54nlqJ-Nx8 ~~~~~ ᕤ OYSTERS ᕤ CLAMS ᕤ AND ᕤ CUCKOLDS ᕤ ~~~~~~ ༼ ᕤ◕◡◕ ༽ᕤ PUNCH HIM ༼ ᕤ◕◡◕ ༽ᕤ
sluggaslamoo
Profile Blog Joined November 2009
Australia4494 Posts
May 29 2014 03:57 GMT
#9687
On May 29 2014 01:10 supereddie wrote:
Show nested quote +
On May 28 2014 12:26 sluggaslamoo wrote:
Be careful about being obsessed over design patterns. The factory pattern is not a appropriate fit for this problem, also the classic factory pattern is quite obtuse, have a look at how ODM's work, they use a much better implementation of the factory pattern.

You do not need a factory to create functions. Functions have their own logic, a factory is not smart enough to create the logic so all it is doing is creating an insertion in the dictionary, hardly useful. Factories are used to facilitate building complex stateful objects, such as instantiating models. You also have a switch statement, which makes the factory redundant. If you are going to use a case-by-case feature for your logic, then you may as well just remove the dictionary altogether.

I only gave an example of how it could be done; I never said this was the only way. As always in programming, there are many ways to solve a problem. I just took one and gave some simplified sample code.

'Functions' do not exists, therefore you cannot create them. Everything is a member of some object. I merely moved the corresponding code to their own classes and gave it a common interface.

I think you misunderstand the sample I gave. It is about abstracting away instantiation of concrete types to the factory. The consumer then only uses the interface (as the consumer shouldn't care about the concrete implementation). This improves maintainability, testability, debugging and a lot more.

If you believe factories are only used to 'facilitate building complex stateful objects' and using a switch statement 'makes the factory redundant', you should read up about common OOP priciples, such as encaspulation and polymorphism.
Show nested quote +
On May 28 2014 12:26 sluggaslamoo wrote:
What you need is reflection, this means you do not need a switch statement, you do not need a dictionary, and you can implement your logic as if it were a normal program.

You don't need to use anything. Use whatever suits your purpose. In this case, I feel reflection is not the right tool. Simply because everything is already known. Therefore you can design your program better, to create a more maintainable, testable and predictable application.

Show nested quote +
On May 28 2014 12:26 sluggaslamoo wrote:
If you want a good example of the factory pattern, have a look at factory_girl.

http://rubydoc.info/gems/factory_girl/1.3.3/frames

That is just one of the many, many possible implementations of a factory pattern. In fact, it behaves more like an Inversion-Of-Control container than a factory. I see a lot of problems with that one page and it's implementation/usage.
Simply trying to create a unit test for a method that uses that 'factory' would be a pain.

Sidenote: I dislike static members as they can't be mocked for unit testing. Avoid static methods at any cost (but if there is a legitimate reason, go ahead).


http://en.wikipedia.org/wiki/Argument_to_moderation

There is usually a best way of doing something. In this case, reflection makes the most sense.

The factory pattern you used is outright redundant. You are creating a whole new base class for something that can already be done very simply.

http://en.wikipedia.org/wiki/You_aren't_gonna_need_it

I don't think you understand design patterns, you wanna use the factory pattern because it is very simple and easy to understand, that doesn't mean its useful.

Look at factory_girl, that is how you should use the factory pattern, not the way the gang of four described, that is unless you want to work on legacy code in C++ and they are indeed creating complex stateful objects for a single class.

A better fit would be through the use of the double-dispatch pattern and strategy or adapter patterns. However these are still unnecessary when you have reflection. If you do not have reflection, you would use the strategy pattern. The double-dispatch would be used for the case-by-case with different models.

Encapsulation and polymorphism has absolutely nothing to do with this. I think it is you that needs to work on your OOP.
Come play Android Netrunner - http://www.teamliquid.net/forum/viewmessage.php?topic_id=409008
sluggaslamoo
Profile Blog Joined November 2009
Australia4494 Posts
Last Edited: 2014-05-29 04:07:03
May 29 2014 04:04 GMT
#9688
On May 29 2014 11:51 FFGenerations wrote:
I'm just throwing together the basis of converting my visual novel to OOP Flash AS3... If you're a Flash/OOP pro and have the time feel free to take a look and comment on this structure while I sleep....
+ Show Spoiler +


[image loading]


a) I have dialoguebox and textbox separate because i think i'll need them to act separately e.g. the dialoguebox doesn't close exactly the same time as the textbox will close.

b) In the diagram i am not showing button functionality e.g. clicking on dialoguebox will progress the text/scene, clicking on options button will store the choice and progress the scene... i'm not sure if i'm supposed to show these things in this diagram? the nature of Flash is confusing me i think, coz these are like inbuilt functions.....

how will i be doing these things? some scene attributes will be pre-set so i guess it will look like.....

displayScene(scene1)
scene1.displayCharacterLeft
scene1.displayCharacterRight
scene1.displayDialogueBox
scene1.displayDialogueText("Yuki: Hi, I'm Yuki")
scene1.displayDialogueText("Gendo: Hello Yuki")
scene1.displayOptionBox
scene1.displayOptions
eventListenerOnClick ->setOptionTrue, hideOptions, displayDialogueText("Nice choice")
endScene(scene1)
displayScene(scene2)

do i want to type out all my game dialogue in the main class rather than in a scene? (i think i do)

maybe someone can simplify the way i should think about this...

disclaimer: i would be doing some bloody flash youtube tutorials but my router broke in a storm and i can barely load youtube at 5k/s on mobile net



screenshot of the game (failed prototype version)
[image loading]





Well its not really OOP, its much more procedural. That doesn't mean its a bad thing, but if you wanna do OO then you will have to think differently.

Basically when thinking about OO you have to think about the taxonomy. Each object must be responsible for itself.

For example, a scene will have many characters. Each character should be responsible for its own display method.

So rather than scene1.displayCharacterLeft

It should be, scene1.left_character.show or visible = true

The scene should be rendering all the characters at once, and the characters should on their own be able to decide whether to be rendered or not.

Same for the GUI components. While the scene contains the GUI components, it should not be responsible for handling the components themselves, the components themselves will have x/y coordinates and be visible or not on their own.

There should probably be an overlay component to contain all the UI, and the scene should be on its own underneath the overlay. Then you should have a controller which handles things like animation such as when the overlay needs to be hidden for specific scenes. The controller would take a list of actions so it knows how to do a full scene animation. Something like that.
Come play Android Netrunner - http://www.teamliquid.net/forum/viewmessage.php?topic_id=409008
mcc
Profile Joined October 2010
Czech Republic4646 Posts
Last Edited: 2014-05-29 04:06:00
May 29 2014 04:05 GMT
#9689
I was wondering how the encapsulation and polymorphism even came up as they have nothing to do with the issue you are discussing.

Anyway factory pattern seems completely unnecessary. Having 10 levels of useless abstractions is not always sign of good solution

Without knowing more specifics it is hard to propose ideal solution, but you can go the string -> function route, but then just have simple function with a switch, factory is of no benefit. Reflection is also easily possible, C# has good enough support for that. Invoke should solve the issue if I understood it correctly.
enigmaticcam
Profile Blog Joined October 2010
United States280 Posts
May 29 2014 15:45 GMT
#9690
I've found the factory pattern quite useful in conjunction with the decorator pattern. Abstracting out the declaration of objects into one location where I'm free to extended with decorators is quite handy.

I would agree that having too many abstractions may not be necessary, but it's really useful in Unit Testing. Having everything abstracted allows you to mock everything you need to isolate a specific set of logic in a way that would otherwise be difficult with concretes.
sluggaslamoo
Profile Blog Joined November 2009
Australia4494 Posts
May 30 2014 02:49 GMT
#9691
On May 30 2014 00:45 enigmaticcam wrote:
I've found the factory pattern quite useful in conjunction with the decorator pattern. Abstracting out the declaration of objects into one location where I'm free to extended with decorators is quite handy.

I would agree that having too many abstractions may not be necessary, but it's really useful in Unit Testing. Having everything abstracted allows you to mock everything you need to isolate a specific set of logic in a way that would otherwise be difficult with concretes.


Again just be really careful about being overly obsessive about the gang of four design patterns. Saying "the factory pattern is quite useful in conjunction with the decorator pattern" is just a really strange way of thinking about programming. Saying your solution is to use the factory pattern just sounds really weird, because the factory pattern is a re-factorizing pattern, it can't actually solve any problems on its own.

Design patterns aren't silver bullets, and these days they are simply there to provide information. In the same way that you are trying to talk about "having everything abstracted" which is really just called functional or object decomposition.

So in that way, I would just tell the person to look at Dijkstra's principles of structured programming or responsibility driven design (for OOP). Its the same as when I tell someone to look at a design pattern, its so I don't have to explain the whole thing.

The main issue with your use of the factory pattern is that its not an abstraction, its just a class which holds the original class's constructor logic. This is why I showed you factory_girl, in that the gang of four factory pattern is not a very good example of the factory pattern and a lot of people get the wrong idea.

A real gang of four factory pattern is able to create a lot of different instances of the same type for a really complex stateful object which would be either really messy or even impossible to write in the constructor. Unless we are working with really old monolithic projects you should never see the factory pattern used in this way.

For smaller projects you want a really dynamic, reusable factory library, and because they already exist, if you want to use the factory pattern, simply use the libraries and save yourself (and everyone else) the pain.

Also be wary about creating abstractions which involve big vertical hierarchies, they will always cause a lot of headaches in the long run. Vertical hierarchies will always cause fragility, Java's stack class is a great example of why their old principle of inheritance was bad and why someone had the knee-jerk reaction of having lots of interfaces instead (which is just as bad).

There is nothing wrong about having lots of concrete classes. Decomposing your program into lots and lots of concrete classes is still abstraction and is much better than having lots of coupled classes layered over each other purely for the sake of "abstraction" and inheritance.

Doing things for the purpose of adhering to "patterns" and "proper design" rather than just solving the problem can often be a silly way of thinking and will often just make you waste time and make the program more fragile and harder to understand than intended.
Come play Android Netrunner - http://www.teamliquid.net/forum/viewmessage.php?topic_id=409008
urboss
Profile Joined September 2013
Austria1223 Posts
Last Edited: 2014-05-30 14:58:06
May 30 2014 09:40 GMT
#9692
nvm
enigmaticcam
Profile Blog Joined October 2010
United States280 Posts
May 30 2014 18:57 GMT
#9693
On May 30 2014 11:49 sluggaslamoo wrote:Doing things for the purpose of adhering to "patterns" and "proper design" rather than just solving the problem can often be a silly way of thinking and will often just make you waste time and make the program more fragile and harder to understand than intended.
While I agree with the part about doing things just because they're the accepted "pattern" or "proper design", that's not why I do them. Properly implemented, they do in fact solve a problem (to an extent): the problem of designing code that's maintainable, flexible, and scalable. But of course, there are any number of ways to do this. The Factory pattern is one way, and it's there for anyone to use if they think it makes sense for their program. If you think your way is better, that's fine. But I think it's a bit silly to dismiss it entirely.
FFGenerations
Profile Blog Joined April 2011
7088 Posts
Last Edited: 2014-05-31 00:35:57
May 31 2014 00:23 GMT
#9694
for newbie programmers and for tutors

i'm half way through this tutorial on basic programming via demonstration in Flash AS3

its fucking BRILLIANT tutorial

you can start at OOP introduction 1 if you're familiar with programming concepts but will need to go back to the very start after that to get familiar with other basics in Flash

it first shows you how to construct a Flash button as a class and then instantiate buttons using your main document class

this is fucking brilliant way of explaining OOP by practical demonstration. its exciting because you know you can apply it to make your own games once you figure it out.

i cant wait to finish this tutorials!!!

http://code.tutsplus.com/series/as3-101--active-7395


ps: thanks for your comment earlier on my problem sluggaslamoo. as you can see i am looking at this tutorial which will help clarify a lot of things i was beginning to query e.g. what a button actually does lol. also as i go back in the tutorial and look at arrays it makes me wonder how i am going to present the mass of dialogue text in the game, whether i want to set it up so i can have lines and lines of
char1 says text
char2 says text
char1 says text
char1 says text
or if there might be a dif way like
print array1.1
print array1.2
print array1.3
idk i need to finish tutorial lol


i wonder if you can make a living making Flash rpgs (this is what i want to do with my life)
Cool BW Music Vid - youtube.com/watch?v=W54nlqJ-Nx8 ~~~~~ ᕤ OYSTERS ᕤ CLAMS ᕤ AND ᕤ CUCKOLDS ᕤ ~~~~~~ ༼ ᕤ◕◡◕ ༽ᕤ PUNCH HIM ༼ ᕤ◕◡◕ ༽ᕤ
sluggaslamoo
Profile Blog Joined November 2009
Australia4494 Posts
Last Edited: 2014-05-31 02:28:09
May 31 2014 02:27 GMT
#9695
On May 31 2014 09:23 FFGenerations wrote:
for newbie programmers and for tutors

i'm half way through this tutorial on basic programming via demonstration in Flash AS3

its fucking BRILLIANT tutorial

you can start at OOP introduction 1 if you're familiar with programming concepts but will need to go back to the very start after that to get familiar with other basics in Flash

it first shows you how to construct a Flash button as a class and then instantiate buttons using your main document class

this is fucking brilliant way of explaining OOP by practical demonstration. its exciting because you know you can apply it to make your own games once you figure it out.

i cant wait to finish this tutorials!!!

http://code.tutsplus.com/series/as3-101--active-7395


ps: thanks for your comment earlier on my problem sluggaslamoo. as you can see i am looking at this tutorial which will help clarify a lot of things i was beginning to query e.g. what a button actually does lol. also as i go back in the tutorial and look at arrays it makes me wonder how i am going to present the mass of dialogue text in the game, whether i want to set it up so i can have lines and lines of
char1 says text
char2 says text
char1 says text
char1 says text
or if there might be a dif way like
print array1.1
print array1.2
print array1.3
idk i need to finish tutorial lol


i wonder if you can make a living making Flash rpgs (this is what i want to do with my life)


Here's an example.

In your scene controller, you would submit an "action list" to it.

An action List takes a list of actions.

An Action takes a character, delay, duration, animation, text, and character_frame. Any of these can be not set, which causes the scene controller to not bother with that aspect.

The character is the character instance so you can get the name and other fields you need, the delay is how long the action takes to begin, duration would be duration of the animation (with a default of 1 second lets say), animation is slide in slide out stuff, if text is there it will be shown, character_frame would correspond to a particular emote the character needs to use.

Your scene controller would go through the list of actions, from top to bottom. It would take both click and duration triggers to trigger the next action until all actions are complete and the scene is over.
Come play Android Netrunner - http://www.teamliquid.net/forum/viewmessage.php?topic_id=409008
FFGenerations
Profile Blog Joined April 2011
7088 Posts
May 31 2014 03:25 GMT
#9696
ah man that is like describing sex to a virgin
get back to you !
Cool BW Music Vid - youtube.com/watch?v=W54nlqJ-Nx8 ~~~~~ ᕤ OYSTERS ᕤ CLAMS ᕤ AND ᕤ CUCKOLDS ᕤ ~~~~~~ ༼ ᕤ◕◡◕ ༽ᕤ PUNCH HIM ༼ ᕤ◕◡◕ ༽ᕤ
FFGenerations
Profile Blog Joined April 2011
7088 Posts
Last Edited: 2014-05-31 08:02:57
May 31 2014 08:00 GMT
#9697
nice now my mom is super pissed off coz i got drunk for the first time in 1-2 years
she is like U HAVE MANY PROBLEMS WHEN I COME BACK FROM HAIRDDRESSER WIE WILL HAVE TO TALK
r u kidding me i just want to sing some anime songs and go to sleep wtf jesus christ
Cool BW Music Vid - youtube.com/watch?v=W54nlqJ-Nx8 ~~~~~ ᕤ OYSTERS ᕤ CLAMS ᕤ AND ᕤ CUCKOLDS ᕤ ~~~~~~ ༼ ᕤ◕◡◕ ༽ᕤ PUNCH HIM ༼ ᕤ◕◡◕ ༽ᕤ
Cyx.
Profile Joined November 2010
Canada806 Posts
May 31 2014 08:10 GMT
#9698
On May 31 2014 17:00 FFGenerations wrote:
nice now my mom is super pissed off coz i got drunk for the first time in 1-2 years
she is like U HAVE MANY PROBLEMS WHEN I COME BACK FROM HAIRDDRESSER WIE WILL HAVE TO TALK
r u kidding me i just want to sing some anime songs and go to sleep wtf jesus christ

fucking parents man
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
May 31 2014 08:16 GMT
#9699
On May 31 2014 09:23 FFGenerations wrote:
its fucking BRILLIANT tutorial

Make sure you don't read this one tutorial and then think you know everything. Learn from multiple sources and critically question each one. Internet tutorials are not something you should blindly depend upon. Neither is any other single source.
If you have a good reason to disagree with the above, please tell me. Thank you.
3FFA
Profile Blog Joined February 2010
United States3931 Posts
May 31 2014 20:35 GMT
#9700
On May 31 2014 17:16 spinesheath wrote:
Show nested quote +
On May 31 2014 09:23 FFGenerations wrote:
its fucking BRILLIANT tutorial

Make sure you don't read this one tutorial and then think you know everything. Learn from multiple sources and critically question each one. Internet tutorials are not something you should blindly depend upon. Neither is any other single source.

What about college/university?
"As long as it comes from a pure place and from a honest place, you know, you can write whatever you want."
Prev 1 483 484 485 486 487 1032 Next
Please log in or register to reply.
Live Events Refresh
Replay Cast
00:00
WardiTV Mondays #62
CranKy Ducklings112
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PiGStarcraft545
elazer 125
Nathanias 69
CosmosSc2 60
StarCraft: Brood War
Artosis 724
Larva 189
Bale 42
Noble 16
Dota 2
monkeys_forever892
NeuroSwarm71
League of Legends
C9.Mang0331
JimRising 280
Other Games
summit1g13100
tarik_tv5255
Day[9].tv799
shahzam515
Maynarde91
Mew2King90
ViBE44
ToD37
Organizations
Other Games
gamesdonequick818
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• Hupsaiya 89
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• RayReign 42
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Doublelift4681
Other Games
• imaqtpie1418
• Day9tv799
Upcoming Events
The PondCast
7h 54m
OSC
13h 54m
Demi vs Mixu
Nicoract vs TBD
Babymarine vs MindelVK
ForJumy vs TBD
Shameless vs Percival
Replay Cast
21h 54m
Korean StarCraft League
2 days
CranKy Ducklings
2 days
WardiTV 2025
2 days
SC Evo League
2 days
BSL 21
2 days
Sziky vs OyAji
Gypsy vs eOnzErG
OSC
2 days
Solar vs Creator
ByuN vs Gerald
Percival vs Babymarine
Moja vs Krystianer
EnDerr vs ForJumy
sebesdes vs Nicoract
Sparkling Tuna Cup
3 days
[ Show More ]
WardiTV 2025
3 days
OSC
3 days
BSL 21
3 days
Bonyth vs StRyKeR
Tarson vs Dandy
Replay Cast
4 days
Wardi Open
4 days
StarCraft2.fi
4 days
Monday Night Weeklies
4 days
Replay Cast
4 days
WardiTV 2025
5 days
StarCraft2.fi
5 days
PiGosaur Monday
5 days
StarCraft2.fi
6 days
Tenacious Turtle Tussle
6 days
Liquipedia Results

Completed

Proleague 2025-11-30
RSL Revival: Season 3
Light HT

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
CSCL: Masked Kings S3
Slon Tour Season 2
Acropolis #4 - TS3
META Madness #9
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
Kuram Kup
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.