Search Results

Search found 42307 results on 1693 pages for 'solid works'.

Page 4/1693 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • 11.10 desktop alerts (volume change and terminal bell) stopped working but all other audio still works

    - by FlabbergastedPickle
    All, My sound works just fine in 11.10 64-bit install on HP dm1-4050 Sandy Bridge notebook (e.g. audio works in Banshee, flash, games, browser, Thunderbird email notification, etc.), but the core desktop notifications (e.g. pressing a tab in a terminal where there is more than one option should trigger a terminal bell, or changing volume using volume keys should be accompanied with the supporting "quack" that the volume app makes) do not work. I've intentionally disabled login sound as explained here on ask ubuntu but even enabling it back makes no difference. These notifications did work before just fine and I am not sure when did the actually stop working but it must've been fairly recently. Only things I did were trying to install some ppa edge xorg drivers for my intel card (a separate issue) but also reverted them all with ppa-purge once I discovered they did not improve anything. Other thing I did was check volume settings with alsamixer and did alsactl store for the soundcard after I did some experimenting with volume settings for PCM (on my laptop PCM at 100% crackles so I had to lower it and make pulseaudio ignore its setting as per ask ubuntu's page). That said, neither of these should have any bearing on the said notifications since the volume is up and they clearly work everywhere else but the core desktop events. The system ready drum sound when Ubuntu boots and user reaches the login screen also does not work. The guest login behaves exactly same as mine. Audio works (including the login sound since I've not disabled it for the guest account), but no quacks when changing the volume or terminal bell sounds... I've tried copying ubuntu sounds to /usr/share/sounds/ as suggested on ask ubuntu and that did not work. I also tried using dconf-editor to check sound theme settings and tried both freedesktop (which is what it was set to) and ubuntu, as suggested on ask ubuntu. This did not work either. I tried purging the ~/.pulse folder and the /tmp/*pulse* entries, rebooting and restarting pulseaudio with -D flag. While audio came back on and behaved just fine in all aspects (e.g. one can adjust volume levels, play music, games, in-browser sound stuff, and other app alerts) except for the system ready drum sound (at the login screen), and any system event (terminal bell and volume change quack sound). It is interesting that the quack sound works inside system settings-sound when adjusting levels there, but it does not when volume is changed via top bar's volume settings... I do recall that at one point yesterday when I was restarting pulseaudio the quacks that accompany volume change did start working but I have no idea what caused that. This was also when I first realized those alerts were not working. After rebooting it was again gone. I did compile my own 3.0.14-rt31 kernel a little while ago as instructed on one of the wiki's for the 11.10 rt kernel. Everything works as before except for the said sound alerts. I am not sure if this began happening since I started using the rt kernel though and yesterday's momentary ability to hear those quacks while changing the volume make me believe that the kernel is not one responsible for this problem. One more thing I can think of is that I used alsoft-conf tool to configure buffering on the OpenAL (due to TA Spring's choppy audio) and changed in there default audio device to ALSA. I also tried reverting it to Pulseaudio as the only allowed output but the bottom part of the Backend tab always reverts to ALSA even when I select Pulseaudio. The pulseaudio does remain as the only active choice on top. This, however, once again does not make any sense in terms of preventing desktop audio alerts when everything else including OpenAL games plays sound just fine... So, there you have it, as verbose as I could make it :-). I tried all I could find on this issue and had no luck so far... Any ideas?

    Read the article

  • Grub Error 18 - Solid State Drive

    - by clint
    I recently used Raw Copy to make an image of my 300gb Raptor Hd to a OCZ Vertex SSD 60GB. And When I pluged in the SSD to boot I get a Grub Error 18. I have tried to changed in the BIOS setting to LBA, Large, Auto, trying different combination's. Any advice. thanks, Clint

    Read the article

  • Want to know how SQL Server logging works?

    - by Jonathan Kehayias
    Have you ever wondered why SQL Server logging works the way it does?  While I have long understood the importance behind the SQL Server Transaction Log, I have never actually understood exactly why it works the way it does, despite having attended Paul Randal’s ( Blog / Twitter ) session at PASS Summit last year.  Over the last few months I have been working on writing a book on troubleshooting the most common problems that I see asked on the forums, and as a part of that I have been digging...(read more)

    Read the article

  • NVIDIA dévoile de nouveaux outils pour les développeurs de jeux vidéo, Flex, Gl Works, Flame Works vont devenir les nouveaux jouets des développeurs

    NVIDIA dévoile de nouveaux outils pour les développeurs de jeux vidéo Flex, Gl Works, Flame Works vont devenir les nouveaux jouets des développeursDurant un événement à Montreal, NVIDIA a présenté de nouveaux outils pour les développeurs de jeux vidéo. Le premier, nommé Flex, s'intègrera aux outils PhysX dès 2014 pour offrir des simulations sur GPU unifiés qui permettra de nouveaux effets comme l'interaction entre les corps solides et les simulations de liquides. Ensuite, la société à dévoilé...

    Read the article

  • JFreeChart - change SeriesStroke of chart lines from solid to dashed in one line

    - by MisterMichaelK
    The answer accepted here (JFreechart(Java) - How to draw lines that is partially dashed lines and partially solid lines?) helped me start down the path of changing my seriesstroke lines on my chart. After stepping through my code and watching the changes, I see that my seriesstroke does in fact change to "dashedStroke" when it is supposed to (after a certain date "dai"), but when the chart is rendered the entire series line is dashed. How can I get a series line to be drawn solid at first and dashed after a set date? /* series line modifications */ final Number dashedAfter = timeNowDate.getTime(); final int dai = Integer.parseInt(ndf.format(timeNowDate)); XYLineAndShapeRenderer render = new XYLineAndShapeRenderer() { Stroke regularStroke = new BasicStroke(); Stroke dashedStroke = new BasicStroke( 1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] {10.0f, 6.0f}, 0.0f ); @Override public Stroke getItemStroke(int row, int column) { Number xVal = cd.getXValue(row, column); int xiv = xVal.intValue(); if (xVal.doubleValue() > dashedAfter.doubleValue()) { return dashedStroke; } else { return regularStroke; } } }; plot.setRenderer(render);

    Read the article

  • webgame engine how does it works

    - by TWCrap
    Hy all, first off all, don't yell that i shouldn't start with it, i just want to know how that works... The thing is, how does the engine of an webgame works. A game like tribalwars, grepolis and forge of empires. How does that keeping alive work. I mean, a user is building an building, and quit the browser... The building is build even when the session of the user is expired. but the points of the user is updated when the building is finished... So how does that works. What do you guys think? do they have some kind of cronjob that is fired every second, and that walks throug the database, and search for finished buildings, and update's the stuff? or do you guys think that they do it difrent?!? I hope that i was clear. -NOTE- i don't need anny code, i'm just intrested in the progress behind the game... Greetingz Marc

    Read the article

  • Is throwing an error in unpredictable subclass-specific circumstances a violation of LSP?

    - by Motti Strom
    Say, I wanted to create a Java List<String> (see spec) implementation that uses a complex subsystem, such as a database or file system, for its store so that it becomes a simple persistent collection rather than an basic in-memory one. (We're limiting it specifically to a List of Strings for the purposes of discussion, but it could extended to automatically de-/serialise any object, with some help. We can also provide persistent Sets, Maps and so on in this way too.) So here's a skeleton implementation: class DbBackedList implements List<String> { private DbBackedList() {} /** Returns a list, possibly non-empty */ public static getList() { return new DbBackedList(); } public String get(int index) { return Db.getTable().getRow(i).asString(); // may throw DbExceptions! } // add(String), add(int, String), etc. ... } My problem lies with the fact that the underlying DB API may encounter connection errors that are not specified in the List interface that it should throw. My problem is whether this violates Liskov's Substitution Principle (LSP). Bob Martin actually gives an example of a PersistentSet in his paper on LSP that violates LSP. The difference is that his newly-specified Exception there is determined by the inserted value and so is strengthening the precondition. In my case the connection/read error is unpredictable and due to external factors and so is not technically a new precondition, merely an error of circumstance, perhaps like OutOfMemoryError which can occur even when unspecified. In normal circumstances, the new Error/Exception might never be thrown. (The caller could catch if it is aware of the possibility, just as a memory-restricted Java program might specifically catch OOME.) Is this therefore a valid argument for throwing an extra error and can I still claim to be a valid java.util.List (or pick your SDK/language/collection in general) and not in violation of LSP? If this does indeed violate LSP and thus not practically usable, I have provided two less-palatable alternative solutions as answers that you can comment on, see below. Footnote: Use Cases In the simplest case, the goal is to provide a familiar interface for cases when (say) a database is just being used as a persistent list, and allow regular List operations such as search, subList and iteration. Another, more adventurous, use-case is as a slot-in replacement for libraries that work with basic Lists, e.g if we have a third-party task queue that usually works with a plain List: new TaskWorkQueue(new ArrayList<String>()).start() which is susceptible to losing all it's queue in event of a crash, if we just replace this with: new TaskWorkQueue(new DbBackedList()).start() we get a instant persistence and the ability to share the tasks amongst more than one machine. In either case, we could either handle connection/read exceptions that are thrown, perhaps retrying the connection/read first, or allow them to throw and crash the program (e.g. if we can't change the TaskWorkQueue code).

    Read the article

  • Body CSS Gradient that Stops and Continues as Solid Color

    - by Alfo
    Something similar to this question has been asked here - HTML/CSS Gradient that stops at a perticular height and continues further with a solid color, but as far as I can see this doesn't work when using it on the body for a background color - which is what I want to achieve. Specifically, I would like it to be light blue at the top of the page, gradient into dark blue 200px further down, and then continue in dark blue for ever. Thanks to anybody who can help, Alfo.

    Read the article

  • Solid Principle examples anywhere?

    - by user231465
    We all write code with some patterns even when we dont realise it. I am trying to really understand some of the solid principles and how you apply this principles in the real world. I am struggling with the "D" my understanding on Dependency Inversion I sometimes confuse with Dependency Injection is that as long as you keep things depending on abstraction (IE:interfaces) you are done. Has anybody got a small c# sample that explains it? thanks

    Read the article

  • Command works partially when run from startup applications

    - by Gaurav Butola
    I have this script (or rather a set of commands which has permission to execute) to enable two finger scrolling and two finger tap = right click The script is located in /home/gaurav/Multigesture/multigesture. When I run the following command in terminal, two finger scrolling and two finger tap = right click start working. I have to run this command each time I boot my laptop. "/home/gaurav/Multigesture/multigesture" So I put this command in the startup applications so that I dont have to run the command each time I boot but when I reboot two finger scrolling is not working, only two finger tap = right click works. What could be the problem, If the command works fine from the terminal then how come it is working partially when i put it into startup applications. Here is the content of the script xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Two-Finger Scrolling" 8 1 xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Scrolling" 8 1 1 xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Pressure" 32 10 xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Width" 32 8 PS. the file which has all the commands (script's) name is multitouch

    Read the article

  • GDD-BR 2010 [1C] Google Web Tookit: What it is, How it Works and Deeper Dives

    GDD-BR 2010 [1C] Google Web Tookit: What it is, How it Works and Deeper Dives Speaker: Chris Ramsdale Track: Cloud Computing Time slot: C [12:05 - 12:50] Room: 1 Level: 151 If you're like the rest of us, at some point in your web app development you've wondered if there was an easier solution. One that includes built-in debuggers, code refactoring, reliable syntax highlighting, etc. After all, why should the server-side and desktop programmers get all of the good tools? The good news is that with Google Web Toolkit (GWT) you do have access to these tools. And in this session, Chris Ramsdale will get you up and running with GWT, including what it is, how it works, and deeper dives into generators, native Javascript interop, and compiler optimizations. From: GoogleDevelopers Views: 1 0 ratings Time: 35:02 More in Science & Technology

    Read the article

  • How a Hard Drive Works in Slow Motion [Video]

    - by Asian Angel
    This short video lets you have a good luck at a hard drive in slow motion as the actuator arm moves across the disk and then water is added to the equation as well… How a Hard Drive works in Slow Motion – The Slow Mo Guys [via BoingBoing] HTG Explains: What Is Two-Factor Authentication and Should I Be Using It? HTG Explains: What Is Windows RT and What Does It Mean To Me? HTG Explains: How Windows 8′s Secure Boot Feature Works & What It Means for Linux

    Read the article

  • Configuring A Subdomain (cPanel) - www works, subdomain on it's own doesn't

    - by Matthew
    I've created a sub domain on my website using cPanel at test.mydomain.com, and this created a folder in my main 'www' directory called test. In this folder is a folder called cgi-bin, and it seems to redirect the page to say "It works!", but when I upload my own index.html file to the test directory it keeps showing http://test.mydomain.com/cgi-sys/defaultwebpage.cgi instead of the index file. If I go to www.test.mydomain.com then it works OK. How do I host my content at the sub domain? It's my first time setting one up so I'm a bit lost.

    Read the article

  • HTG Explains: How System Restore Works in Windows

    - by Chris Hoffman
    System Restore is a Windows feature that can help fix some crashes and other computer problems. To know when to use it, you’ll have to understand just how System Restore works. System Restore can’t solve every problem – for example, you can’t use it to restore your personal files if they’re accidentally deleted or modified. However, it’s another tool you can use when your computer isn’t working properly. HTG Explains: How Antivirus Software Works HTG Explains: Why Deleted Files Can Be Recovered and How You Can Prevent It HTG Explains: What Are the Sys Rq, Scroll Lock, and Pause/Break Keys on My Keyboard?

    Read the article

  • Solid FFmpeg wrapper for C#/.NET

    - by Lillemanden
    I have been searching the web for some time for a solid FFmpeg wrapper for C#/.NET. But I have yet to come up with something useful. I have found the following three projects, but all of them apears to be dead in early alpha stage. FFmpeg.NET ffmpeg-sharp FFLIB.NET So my question is if anyone knows of a wrapper project that is more mature? I am not looking for a full transcoding engine with job queues and more. Just a simple wrapper so I do not have to make a command line call and then parse the console output, but can make method calls and use eventlisteners for progress. And please feel free to mention any active projects, even if they are stil in the early stages.

    Read the article

  • Lexmark X5650 doesn't print (scanning works)

    - by unor
    I want to use a Lexmark X5650 under Ubuntu. When I connect it via USB, Ubuntu recognizes the device, but can't find a driver. On the Lexmark support site, you can select "Unix/Linux" and then "Ubuntu 9.04", "9.10", "10.04" and "10.10". However, all versions lead to the same driver: lexmark-08z-series-driver-1.0-1.i386.deb.sh.tar.gz (Last updated: 2012-04-13). While installing this driver, the installer asks me to connect the device. As soon as I connect it via USB, Ubuntu now adds the printer automatically. So after the installation completed, I had 2 printers set up. But I can't print anything (I tried it with both printer configurations). Scanning works fine, though. So I guess the driver installation and the device connection are successful. When I try to print something, the print job is listed in the printing queue, but nothing happens. After some time, I get an error message which starts a debug wizard, but in the end it reads something like "Sorry, couldn't find the reason". I had several different error messages (unfortunately, I didn't record them), one was approximately like "printer cannot communicate with computer". Another said that my color ink was low (which is true, but black is full). Another said there was an input/output error. I tried it with Ubuntu 11.10. Because I read that some people had success with 10.04., I installed it in QEMU and installed the driver there, too. Same problem, though. I'd like to upgrade to 12.04, if it should work there for any reason, but I read that for some people this printer stopped working in 12.04 :/ So, it would be best if the printer would work in 12.04. If that's not possible, I'd be fine with starting a QEMU virtual machine with any GNU/Linux distribution that works with my printer.

    Read the article

  • Is "as long as it works" the norm?

    - by q303
    Hi, My last shop did not have a process. Agile essentially meant they did not have a plan at all about how to develop or manage their projects. It meant "hey, here's a ton of work. Go do it in two weeks. We're fast paced and agile." They released stuff that they knew had problems. They didn't care how things were written. There were no code reviews--despite there being several developers. They released software they knew to be buggy. At my previous job, people had the attitude as long as it works, it's fine. When I asked for a rewrite of some code I had written while we were essentially exploring the spec, they denied it. I wanted to rewrite the code because code was repeated in multiple places, there was no encapsulation and it took people a long time to make changes to it. So essentially, my impression is this: programming boils down to the following: Reading some book about the latest tool/technology Throwing code together based on this, avoiding writing any individual code because the company doesn't want to "maintain custom code" Showing it and moving on to the next thing, "as long as it works." I've always told myself that next job I'm going to get a better shop. It never happens. If this is it, then I feel stuck. The technologies always change; if the only professional development here is reading the latest MS Press technology book, then what have you built in 10 years but a superficial knowledge of various technologies? I'm concerned about: Best way to have professional standards How to develop meaningful knowledge and experience in this situation

    Read the article

  • Custom daemon script: works, but does not run at boot / startup

    - by pearjoint
    this is Ubuntu 10.10 Maverick. I have the following shell script in init.d that I want to run as a "daemon" (background service with start/stop/restart really) at system startup. There is a symlink in rc3.d. I tried 4 and 5 too. (Ideally this would initialize before graphical login happens and before a user logs in.) IMPORTANT: the script works 100% as expected and required when testing this with service MetaLeapDaemon start and service MetaLeapDaemon stop. (This shell script calls a Python program which makes sure the appropriate .pid files are both created at startup and deleted at exit.) So generally it works fine but now my only issue is why it will not be run at any of the run-levels I tried. I know for sure it isn't run because the log file it normally creates does not get created. As you can see (by the lack of any uid:gid args in the start-stop-daemon commands) this would currently run only under root, is this forbidden in a default setup? Here's the script, pretty much your run-off-the-mill daemon script really: #! /bin/sh DAEMON=/opt/metaleap/_core/daemon/MetaLeapDaemon.py NAME=MetaLeapDaemon DESC="MetaLeapDaemon" test -f $DAEMON || exit 0 set -e case "$1" in start) start-stop-daemon --start --pidfile /var/run/$NAME.pid --exec $DAEMON ;; stop) start-stop-daemon --stop --pidfile /var/run/$NAME.pid ;; restart) start-stop-daemon --stop --pidfile /var/run/$NAME.pid sleep 1 start-stop-daemon --start --pidfile /var/run/$NAME.pid --exec $DAEMON ;; *) N=/etc/init.d/$NAME echo "Usage: $N {start|stop|restart}" >&2 exit 1 ;; esac exit 0

    Read the article

  • Liskov substitution and abstract classes / strategy pattern

    - by Kolyunya
    I'm trying to follow LSP in practical programming. And I wonder if different constructors of subclasses violate it. It would be great to hear an explanation instead of just yes/no. Thanks much! P.S. If the answer is no, how do I make different strategies with different input without violating LSP? class IStrategy { public: virtual void use() = 0; }; class FooStrategy : public IStrategy { public: FooStrategy(A a, B b) { c = /* some operations with a, b */ } virtual void use() { std::cout << c; } private: C c; }; class BarStrategy : public IStrategy { public: BarStrategy(D d, E e) { f = /* some operations with d, e */ } virtual void use() { std::cout << f; } private: F f; };

    Read the article

  • Examples of Liskov Substitution

    - by james lewis
    I'm facilitating a session next week on the Liskov Substitution Principle and I was wondering if anyone had any examples of violations 'from the trenches'? I'm looking for something other than uncle Bob's rectangle - square problem and the persistent set problem he talks about in A-PPP (although that is a great example). So far I'm using the example of a (very simple) List and an IndexedList as the 'correct' use of inheritance. And the addition of a Set to this hierarchy as a violation (as a Set is distinct; strengthening the pre condition of the Add method). I've also taken this great example and it's solution from this question Both those examples are great but I'm looking for something more subtle and harder to spot. So far I've come up with nothing so if you've got a great, subtle example post it up. Also, any metaphors you've come across that helped you understand LSP would be really useful too.

    Read the article

  • Liskov principle: violation by type-hinting

    - by Elias Van Ootegem
    According to the Liskov principle, a construction like the one below is invalid, as it strengthens a pre-condition. I know the example is pointless/nonsense, but when I last asked a question like this, and used a more elaborate code sample, it seemed to distract people too much from the actual question. //Data models abstract class Argument { protected $value = null; public function getValue() { return $this->value; } abstract public function setValue($val); } class Numeric extends Argument { public function setValue($val) { $this->value = $val + 0;//coerce to number return $this; } } //used here: abstract class Output { public function printValue(Argument $arg) { echo $this->format($arg); return $this; } abstract public function format(Argument $arg); } class OutputNumeric extends Output { public function format(Numeric $arg)//<-- VIOLATION! { $format = is_float($arg->getValue()) ? '%.3f' : '%d'; return sprintf($format, $arg->getValue()); } } My question is this: Why would this kind of "violation" be considered harmful? So much so that some languages, like the one I used in this example (PHP), don't even allow this? I'm not allowed to strengthen the type-hint of an abstract method but, by overriding the printValue method, I am allowed to write: class OutputNumeric extends Output { final public function printValue(Numeric $arg) { echo $this->format($arg); } public function format(Argument $arg) { $format = is_float($arg->getValue()) ? '%.3f' : '%d'; return sprintf($format, $arg->getValue()); } } But this would imply repeating myself for each and every child of Output, and makes my objects harder to reuse. I understand why the Liskov principle exists, don't get me wrong, but I find it somewhat difficult to fathom why the signature of an abstract method in an abstract class has to be adhered to so much stricter than a non-abstract method. Could someone explain to me why I'm not allowed to hind at a child class, in a child class? The way I see it, the child class OutputNumeric is a specific use-case of Output, and thus might need a specific instance of Argument, namely Numeric. Is it really so wrong of me to write code like this?

    Read the article

  • Where should you put constants and why?

    - by Tim Meyer
    In our mostly large applications, we usually have a only few locations for constants: One class for GUI and internal contstants (Tab Page titles, Group Box titles, calculation factors, enumerations) One class for database tables and columns (this part is generated code) plus readable names for them (manually assigned) One class for application messages (logging, message boxes etc) The constants are usually separated into different structs in those classes. In our C++ applications, the constants are only defined in the .h file and the values are assigned in the .cpp file. One of the advantages is that all strings etc are in one central place and everybody knows where to find them when something must be changed. This is especially something project managers seem to like as people come and go and this way everybody can change such trivial things without having to dig into the application's structure. Also, you can easily change the title of similar Group Boxes / Tab Pages etc at once. Another aspect is that you can just print that class and give it to a non-programmer who can check if the captions are intuitive, and if messages to the user are too detailed or too confusing etc. However, I see certain disadvantages: Every single class is tightly coupled to the constants classes Adding/Removing/Renaming/Moving a constant requires recompilation of at least 90% of the application (Note: Changing the value doesn't, at least for C++). In one of our C++ projects with 1500 classes, this means around 7 minutes of compilation time (using precompiled headers; without them it's around 50 minutes) plus around 10 minutes of linking against certain static libraries. Building a speed optimized release through the Visual Studio Compiler takes up to 3 hours. I don't know if the huge amount of class relations is the source but it might as well be. You get driven into temporarily hard-coding strings straight into code because you want to test something very quickly and don't want to wait 15 minutes just for that test (and probably every subsequent one). Everybody knows what happens to the "I will fix that later"-thoughts. Reusing a class in another project isn't always that easy (mainly due to other tight couplings, but the constants handling doesn't make it easier.) Where would you store constants like that? Also what arguments would you bring in order to convince your project manager that there are better concepts which also comply with the advantages listed above? Feel free to give a C++-specific or independent answer. PS: I know this question is kind of subjective but I honestly don't know of any better place than this site for this kind of question. Update on this project I have news on the compile time thing: Following Caleb's and gbjbaanb's posts, I split my constants file into several other files when I had time. I also eventually split my project into several libraries which was now possible much easier. Compiling this in release mode showed that the auto-generated file which contains the database definitions (table, column names and more - more than 8000 symbols) and builds up certain hashes caused the huge compile times in release mode. Deactivating MSVC's optimizer for the library which contains the DB constants now allowed us to reduce the total compile time of your Project (several applications) in release mode from up to 8 hours to less than one hour! We have yet to find out why MSVC has such a hard time optimizing these files, but for now this change relieves a lot of pressure as we no longer have to rely on nightly builds only. That fact - and other benefits, such as less tight coupling, better reuseability etc - also showed that spending time splitting up the "constants" wasn't such a bad idea after all ;-)

    Read the article

  • Avoiding coupling

    - by Seralize
    It is also true that a system may become so coupled, where each class is dependent on other classes that depend on other classes, that it is no longer possible to make a change in one place without having a ripple effect and having to make subsequent changes in many places.[1] This is why using an interface or an abstract class can be valuable in any object-oriented software project. Quote from Wikipedia Starting from scratch I'm starting from scratch with a project that I recently finished because I found the code to be too tightly coupled and hard to refactor, even when using MVC. I will be using MVC on my new project aswell but want to try and avoid the pitfalls this time, hopefully with your help. Project summary My issue is that I really wish to keep the Controller as clean as possible, but it seems like I can't do this. The basic idea of the program is that the user picks wordlists which is sent to the game engine. It will pick random words from the lists until there are none left. Problem at hand My main problem is that the game will have 'modes', and need to check the input in different ways through a method called checkWord(), but exactly where to put this and how to abstract it properly is a challenge to me. I'm new to design patterns, so not sure whether there exist any might fit my problem. My own attempt at abstraction Here is what I've gotten so far after hours of 'refactoring' the design plans, and I know it's long, but it's the best I could do to try and give you an overview (Note: As this is the sketch, anything is subject to change, all help and advice is very welcome. Also note the marked coupling points): Wordlist class Wordlist { // Basic CRUD etc. here! // Other sample methods: public function wordlistCount($user_id) {} // Returns count of how many wordlists a user has public function getAll($user_id) {} // Returns all wordlists of a user } Word class Word { // Basic CRUD etc. here! // Other sample methods: public function wordCount($wordlist_id) {} // Returns count of words in a wordlist public function getAll($wordlist_id) {} // Returns all words from a wordlist public function getWordInfo($word_id) {} // Returns information about a word } Wordpicker class Wordpicker { // The class needs to know which words and wordlists to exclude protected $_used_words = array(); protected $_used_wordlists = array(); // Wordlists to pick words from protected $_wordlists = array(); /* Public Methods */ public function setWordlists($wordlists = array()) {} public function setUsedWords($used_words = array()) {} public function setUsedWordlists($used_wordlists = array()) {} public function getRandomWord() {} // COUPLING POINT! Will most likely need to communicate with both the Wordlist and Word classes /* Protected Methods */ protected function _checkAvailableWordlists() {} // COUPLING POINT! Might need to check if wordlists are deleted etc. protected function _checkAvailableWords() {} // COUPLING POINT! Method needs to get all words in a wordlist from the Word class } Game class Game { protected $_session_id; // The ID of a game session which gets stored in the database along with game details protected $_game_info = array(); // Game instantiation public function __construct($user_id) { if (! $this->_session_id = $this->_gameExists($user_id)) { // New game } else { // Resume game } } // This is the method I tried to make flexible by using abstract classes etc. // Does it even belong in this class at all? public function checkWord($answer, $native_word, $translation) {} // This method checks the answer against the native word / translation word, depending on game mode public function getGameInfo() {} // Returns information about a game session, or creates it if it does not exist public function deleteSession($session_id) {} // Deletes a game session from the database // Methods dealing with game session information protected function _gameExists($user_id) {} protected function _getProgress($session_id) {} protected function _updateProgress($game_info = array()) {} } The Game /* CONTROLLER */ /* "Guess the word" page */ // User input $game_type = $_POST['game_type']; // Chosen with radio buttons etc. $wordlists = $_POST['wordlists']; // Chosen with checkboxes etc. // Starts a new game or resumes one from the database $game = new Game($_SESSION['user_id']); $game_info = $game->getGameInfo(); // Instantiates a new Wordpicker $wordpicker = new Wordpicker(); $wordpicker->setWordlists((isset($game_info['wordlists'])) ? $game_info['wordlists'] : $wordlists); $wordpicker->setUsedWordlists((isset($game_info['used_wordlists'])) ? $game_info['used_wordlists'] : NULL); $wordpicker->setUsedWords((isset($game_info['used_words'])) ? $game_info['used_words'] : NULL); // Fetches an available word if (! $word_id = $wordpicker->getRandomWord()) { // No more words left - game over! $game->deleteSession($game_info['id']); redirect(); } else { // Presents word details to the user $word = new Word(); $word_info = $word->getWordInfo($word_id); } The Bit to Finish /* CONTROLLER */ /* "Check the answer" page */ // ?????????????????? ( http://pastebin.com/cc6MtLTR ) Make sure you toggle the 'Layout Width' to the right for a better view. Thanks in advance. Questions To which extent should objects be loosely coupled? If object A needs info from object B, how is it supposed to get this without losing too much cohesion? As suggested in the comments, models should hold all business logic. However, as objects should be independent, where to glue them together? Should the model contain some sort of "index" or "client" area which connects the dots? Edit: So basically what I should do for a start is to make a new model which I can more easily call with oneliners such as $model->doAction(); // Lots of code in here which uses classes! How about the method for checking words? Should it be it's own object? I'm not sure where I should put it as it's pretty much part of the 'game'. But on another hand, I could just leave out the 'abstraction and OOPness' and make it a method of the 'client model' which will be encapsulated from the controller anyway. Very unsure about this.

    Read the article

  • Liskov substitution principle with abstract parent class

    - by Songo
    Does Liskov substitution principle apply to inheritance hierarchies where the parent is an abstract class the same way if the parent is a concrete class? The Wikipedia page list several conditions that have to be met before a hierarchy is deemed to be correct. However, I have read in a blog post that one way to make things easier to conform to LSP is to use abstract parent instead of a concrete class. How does the choice of the parent type (abstract vs concrete) impacts the LSP? Is it better to have an abstract base class whenever possible?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >