Search Results

Search found 1449 results on 58 pages for 'oop'.

Page 21/58 | < Previous Page | 17 18 19 20 21 22 23 24 25 26 27 28  | Next Page >

  • Why Directly Accesing property is not recommended in OOPs PHP?

    - by Parth
    If I have a class "person" with a property $name and its getter(get_name()) and setter(set_name()) methods, then after instantiating the objects and setting the property i.e. $paddy = new person(); $paddy->set_name("Padyster Dave"); echo "Paddy's full name: ".$paddy->name; //WHY THIS IS NOT RECOMMENDED... In the above code $paddy->name;WHY THIS IS NOT RECOMMENDED?

    Read the article

  • Is Form validation and Business validation too much?

    - by Robert Cabri
    I've got this question about form validation and business validation. I see a lot of frameworks that use some sort of form validation library. You submit some values and the library validates the values from the form. If not ok it will show some errors on you screen. If all goes to plan the values will be set into domain objects. Here the values will be or, better said, should validated (again). Most likely the same validation in the validation library. I know 2 PHP frameworks having this kind of construction Zend/Kohana. When I look at programming and some principles like Don't Repeat Yourself (DRY) and single responsibility principle (SRP) this isn't a good way. As you can see it validates twice. Why not create domain objects that do the actual validation. Example: Form with username and email form is submitted. Values of the username field and the email field will be populated in 2 different Domain objects: Username and Email class Username {} class Email {} These objects validate their data and if not valid throw an exception. Do you agree? What do you think about this aproach? Is there a better way to implement validations? I'm confused about a lot of frameworks/developers handling this stuff. Are they all wrong or am I missing a point? Edit: I know there should also be client side kind of validation. This is a different ballgame in my Opinion. If You have some comments on this and a way to deal with this kind of stuff, please provide.

    Read the article

  • How Can I Learn when to build my own Interfaces

    - by BDotA
    I am using C# and I know what are the interfaces and how syntatically use them,etc. but what I have not learned yet is that when I am tasked to write a project, create a component,... How should I learn better about interfaces so when I want to do something I be able to Think about using them in my design...or for example I want to learn about dependency injection or even using mocking objects for testing, these are all related to good understanding of interfaces and know when and how to use them ... Can you plase provide me some good advice, reading,... then can help me with that?

    Read the article

  • Make is more OOPey - good structure?

    - by Tom
    Hi, I just want advice on whether I could improve structure around a particular class which handles all disk access functions The structure of my program is that I have a class called Disk which gets data from flatfiles and databases on a, you guessed it, hard disk drive. I have functions like LoadTextFileToStringList, WriteStringToTextFile, DeleteLineInTextFile etc which are kind of "generic methods" In the same class I also have some more specific methods such as GetXFromDisk where X might be a particular field in a database table/query. Should I separate out the generic methods from the specialised. Should I make another class which inherits the generic methods. At the moment my class is static as there is no need to have an internal state of the class. I'm not really OOPing am I? Thanks Thomas

    Read the article

  • Which version of Grady Booch's OOA/D book should I buy?

    - by jackj
    Grady Booch's "Object-Oriented Analysis and Design with Applications" is available brand new in both the 2nd edition (1993) and the 3rd edition (2007), while many used copies of both editions are available. Here are my concerns: 1) The 2nd edition uses C++: given that I just finished reading my first two C++ books (Accelerated C++ and C++ Primer) I guess practical tips can only help, so the 2nd edition is probably best (I think the 3rd edition has absolutely no code). On the other hand, the C++ books I read insist on the importance of using standard C++, whereas Booch's 2nd edition was published before the 1998 standard. 2) The 2nd edition is shorter (608 pages vs. 720) so, I guess, it will be slightly easier to get through. 3) The 3rd edition uses UML 2.0, whereas the 2nd edition is pre-UML. Some reviews say that the notation in the 2nd edition is close enough to UML, so it doesn't matter, but I don't know if I should be worrying about this or not. 4) The 2nd edition is available in good-shape used copies for considerably less than what the 3rd one goes for. Given all the above factors, do you think I should buy the 2nd or the 3rd edition? Recommendations on other books are also welcome but I would prefer it if whoever answers has read at least one of the versions of Booch's book (preferably both!). I have already bought but not read GoF and Riel's books. I also know that I should practice a lot with real-life code. Thanks.

    Read the article

  • Logic behind plugin system?

    - by Danijel
    I have an application in PHP (private CMS) that I would like to rewrite and add some new things - I would like to be able to extend my app in an easier way - through plugins But the problem is - I don't know how to achieve "pluggability", how to make system that recognizes plugins and injects them into the app? So, what's the logic of a simple plugin system?

    Read the article

  • Add additional content to the middle of string from within a method

    - by Sammy T
    I am working with a log file and I have a method which is creating a generic entry in to the log. The generic log entry looks like this: public StringBuilder GetLogMessage(LogEventType logType, object message) { StringBuilder logEntry = new StringBuilder(); logEntry.AppendFormat("DATE={0} ", DateTime.Now.ToString("dd-MMM-yyyy", new CultureInfo(CommonConfig.EnglishCultureCode))); logEntry.AppendFormat("TIME={0} ", DateTime.Now.ToString("HH:mm:ss", new CultureInfo(CommonConfig.EnglishCultureCode))); logEntry.AppendFormat("ERRORNO={0} ", base.RemoteIPAddress.ToString().Replace(".", string.Empty)); logEntry.AppendFormat("IP={0}", base.RemoteIPAddress.ToString()); logEntry.AppendFormat("LANG={0} ", base.Culture.TwoLetterISOLanguageName); logEntry.AppendFormat("PNR={0} ", this.RecordLocator); logEntry.AppendFormat("AGENT={0} ", base.UserAgent); logEntry.AppendFormat("REF={0} ", base.Referrer); logEntry.AppendFormat("SID={0} ", base.CurrentContext.Session.SessionID); logEntry.AppendFormat("LOGTYPE={0} ", logType.ToString() ); logEntry.AppendFormat("MESSAGE={0} ", message); return logEntry; } What would be the best approach for adding additional parameters before "MESSAGE="? For example if I wanted to add "MODULE=" from a derived class when the GetLogMessage is being run. Would a delegate be what I am looking for or marking the method as virtual and overriding it or do I need something entirely different? Any help would be appreciated.

    Read the article

  • dynamic behavior of factory class

    - by manu1001
    I have a factory class that serves out a bunch of properties. Now, the properties might come either from a database or from a properties file. This is what I've come up with. public class Factory { private static final INSTANCE = new Factory(source); private Factory(DbSource source) { // read from db, save properties } private Factory(FileSource source) { // read from file, save properties } // getInstance() and getProperties() here } What's a clean way of switching between these behaviors based on the environment. I want to avoid having to recompile the class each time.

    Read the article

  • How do you keep yourself and your co-workers from creating huge classes

    - by PieterG
    Stackoverflow users, How do you keep yourself from creating large classes with large bodied methods. When deadlines are tight, you end up trying to hack things together and it ends up being a mess which would need to be refactored. For me, the one way was to start with test driven development and that lends itself to good class design as well as the SRP (Single Responsibility Principle). I also see developers just double clicking on controls and typing out line after line in the event method that gets fired. What are your suggestions?

    Read the article

  • OO vs Simplicity when it comes to user interaction

    - by Oetzi
    Firstly, sorry if this question is rather vague but it's something I'd really like an answer to. As a project over summer while I have some downtime from Uni I am going to build a monopoly game. This question is more about the general idea of the problem however, rather than the specific task I'm trying to carry out. I decided to build this with a bottom up approach, creating just movement around a forty space board and then moving on to interaction with spaces. I realised that I was quite unsure of the best way of proceeding with this and I am torn between two design ideas: Giving every space its own object, all sub-classes of a Space object so the interaction can be defined by the space object itself. I could do this by implementing different land() methods for each type of space. Only giving the Properties and Utilities (as each property has unique features) objects and creating methods for dealing with the buying/renting etc in the main class of the program (or Board as I'm calling it). Spaces like go and super tax could be implemented by a small set of conditionals checking to see if player is on a special space. Option 1 is obviously the OO (and I feel the correct) way of doing things but I'd like to only have to handle user interaction from the programs main class. In other words, I don't want the space objects to be interacting with the player. Why? Errr. A lot of the coding I've done thus far has had this simplicity but I'm not sure if this is a pipe dream or not for larger projects. Should I really be handling user interaction in an entirely separate class? As you can see I am quite confused about this situation. Is there some way round this? And, does anyone have any advice on practical OO design that could help in general?

    Read the article

  • actionscript-3: refactor interface inheritance to get rid of ambiguous reference error

    - by maxmc
    hi! imagine there are two interfaces arranged via composite pattern, one of them has a dispose method among other methods: interface IComponent extends ILeaf { ... function dispose() : void; } interface ILeaf { ... } some implementations have some more things in common (say an id) so there are two more interfaces: interface ICommonLeaf extends ILeaf { function get id() : String; } interface ICommonComponent extends ICommonLeaf, IComponent { } so far so good. but there is another interface which also has a dispose method: interface ISomething { ... function dispose() : void; } and ISomething is inherited by ICommonLeaf: interface ICommonLeaf extends ILeaf, ISomething { function get id() : String; } As soon as the dispose method is invoked on an instance which implements the ICommonComponent interface, the compiler fails with an ambiguous reference error because ISomething has a method called dispose and ILeaf also has a dispose method, both living in different interfaces (IComponent, ISomething) within the inheritace tree of ICommonComponent. I wonder how to deal with the situation if the IComponent, the ILeaf and the ISomething can't change. the composite structure must also work for for the ICommonLeaf & ICommonComponent implementations and the ICommonLeaf & ICommonComponent must conform to the ISomething type. this might be an actionscript-3 specific issue. i haven't tested how other languages (for instance java) handle stuff like this.

    Read the article

  • How can i use complextype class or multi type class is it generic collection?

    - by programmerist
    i need a complex returning type. i have 4 class returning types COMPLEXTYPE must include Company, Muayene, Radyoloji, Satis because i must return data switch case situation how can i do? Maybe i need generic collections How can i do that? public class GenoTipController { public COMPLEXTYPE Generate(DataModelType modeltype) { _Company company = null; _Muayene muayene = null; _Radyoloji radyoloji = null; _Satis satis = null; switch (modeltype) { case DataModelType.Radyoloji: radyoloji = new Radyoloji(); return radyoloji; break; case DataModelType.Satis: satis = new Satis(); return satis; break; case DataModelType.Muayene: muayene = new Muayene(); return muayene; break; case DataModelType.Company: company = new Company(); return company; break; default: break; } } } public class CompanyView { public static List GetPersonel() { GenoTipController controller = new GenoTipController(); _Company company = controller.Generate(DataModelType.Company); return company.GetPersonel(); } } public enum DataModelType { Radyoloji, Satis, Muayene, Company }

    Read the article

  • Setting javascript prototype function within object class declaration

    - by Tauren
    Normally, I've seen prototype functions declared outside the class definition, like this: function Container(param) { this.member = param; } Container.prototype.stamp = function (string) { return this.member + string; } var container1 = new Container('A'); alert(container1.member); alert(container1.stamp('X')); This code produces two alerts with the values "A" and "AX". I'd like to define the prototype function INSIDE of the class definition. Is there anything wrong with doing something like this? function Container(param) { this.member = param; if (!Container.prototype.stamp) { Container.prototype.stamp = function() { return this.member + string; } } } I was trying this so that I could access a private variable in the class. But I've discovered that if my prototype function references a private var, the value of the private var is always the value that was used when the prototype function was INITIALLY created, not the value in the object instance: Container = function(param) { this.member = param; var privateVar = param; if (!Container.prototype.stamp) { Container.prototype.stamp = function(string) { return privateVar + this.member + string; } } } var container1 = new Container('A'); var container2 = new Container('B'); alert(container1.stamp('X')); alert(container2.stamp('X')); This code produces two alerts with the values "AAX" and "ABX". I was hoping the output would be "AAX" and "BBX". I'm curious why this doesn't work, and if there is some other pattern that I could use instead.

    Read the article

  • Get list of Class names in package

    - by TandemAdam
    Is there any way I can get a list of all the classes in a particular package? I know getDefinitionByName, getQualifiedClassName, and getQualifiedSuperclassName in flash.utils can find me a class, but I can't find anyway to find all the classes in a package at runtime.

    Read the article

  • Suggest the way to design several classes

    - by Oleg Tarasenko
    Hi, I'm building simple application on as3. Kind of starship game. What I want to do is to create several different star ships. Each one should have different images (different look), different sets of animation (e.g. when it's flying, burning, damaged), different kind of weapon and also different controllers (e.g. one can be managed by user, another one by computer, and I want to be able to reuse same ships for AI controller as well as for users controls). Each ship is created in the following way: Create entity Add spatial Add renderers Add other components.... ...... n. init the ship So what I am trying to do: 1) Create StarShip superclass, to store HP (as every ship has it), store spatial (same reason) 2) Create inherited class for any other ship... (It will contain renderer - (responsible for display part), weapon, set of animations), etc What do you think about such way of composition? Maybe it's better to place everything in super class, and then just create instances using long, long, long constructors like: StarShip(hp:HP, animations:DICT, weapon:Weapon, ....) Need advice

    Read the article

  • In Ruby, how can I initialize instance variables in new objects of core classes created from literal

    - by Ollie Saunders
    class Object attr_reader :foo def initialize @foo = 'bar' end end Object.new.foo # => 'bar' ''.foo # => nil //.foo # => nil [].foo # => nil I want them all to return 'bar' Am aware that you can do this already: class Object def foo 'bar' end end But I specifically want to initialize a state variable. Also note that this doesn't work. class String alias_method :old_init, :initialize def initialize(*args) super old_init(*args) end end class Object attr_reader :foo def initialize @foo = 'bar' super end end ''.foo # => nil Nor does this: class String attr_reader :foo def initialize @foo = 'bar' end end ''.instance_variables # => [] I'm beginning to think that this isn't actually possible.

    Read the article

  • Generic overriding tells me this is the same function. Not agree.

    - by serhio
    base class: Class List(Of T) Function Contains(ByVal value As T) As Boolean derived class: Class Bar : List(Of Exception) ' Exception type as example ' Function Contains(Of U)(ByVal value As U) As Boolean compiler tells me that that two are the same, so I need to declare Overloads/new this second function. But I want use U to differentiate the type (one logic) like NullReferenceException, ArgumentNull Exception, etc. but want to leave the base function(no differentiation by type - other logic) as well.

    Read the article

  • A Question on Encapsulation.

    - by Bragaadeesh
    Hi, I know that encapsulation is binding the members and its behavior in one single entity. And it has made me think that the members have to be private. Does this mean if a class having public members is not following 100% Encapsulation rule? Thanks

    Read the article

< Previous Page | 17 18 19 20 21 22 23 24 25 26 27 28  | Next Page >