Search Results

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

Page 9/58 | < Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • php oop and mysql

    - by gloris
    I need to get data, to check and send to db. Programming with PHP OOP. Could you tell me if my class structure is good and how dislpay all data?. Thanks <?php class Database{ private $DBhost = 'localhost'; private $DBuser = 'root'; private $DBpass = 'root'; private $DBname = 'blog'; public function connect(){ //Connect to mysql db } public function select($rows){ //select data from db } public function insert($rows){ //Insert data to db } public function delete($rows){ //Delete data from db } } class CheckData{ public $number1; public $number2; public function __construct(){ $this->number1 = $_POST['number1']; $this->number2 = $_POST['number2']; } function ISempty(){ if(!empty($this->$number1)){ echo "Not Empty"; $data = new Database(); $data->insert($this->$number1); } else{ echo "Empty1"; } if(!empty($this->$number2)){ echo "Not Empty"; $data = new Database(); $data->insert($this->$number2); } else{ echo "Empty2"; } } } class DisplayData{ //How print all data? function DisplayNumber(){ $data = new Database(); $data->select(); } } $check = new CheckData(); $check->ISempty(); $display = new DisplayData() $display->DisplayNumber(); ?>

    Read the article

  • Initialize a Variable Again.

    - by SoulBeaver
    That may sound a little confusing. Basically, I have a function CCard newCard() { /* Used to store the string variables intermittantly */ std::stringstream ssPIN, ssBN; int picker1, picker2; int pin, bankNum; /* Choose 5 random variables, store them in stream */ for( int loop = 0; loop < 5; ++loop ) { picker1 = rand() % 8 + 1; picker2 = rand() % 8 + 1; ssPIN << picker1; ssBN << picker2; } /* Convert them */ ssPIN >> pin; ssBN >> bankNum; CCard card( pin, bankNum ); return card; } that creates a new CCard variable and returns it to the caller CCard card = newCard(); My teacher advised me that doing this is a violation of OOP principles and has to be put in the class. He told me to use this method as a constructor. Which I did: CCard::CCard() { m_Sperre = false; m_Guthaben = rand() % 1000; /* Work */ /* Convert them */ ssPIN >> m_Geheimzahl; ssBN >> m_Nummer; } All variables with m_ are member variables. However, the constructor works when I initialize the card normally CCard card(); at the start of the program. However, I also have a function, that is supposed to create a new card and return it to the user, this function is now broken. The original command: card = newCard(); isn't available anymore, and card = new CCard(); doesn't work. What other options do I have? I have a feeling using the constructor won't work, and that I probably should just create a class method newCard, but I want to see if it is somehow at all possible to do it the way the teacher wanted. This is creating a lot of headaches for me. I told the teacher that this is a stupid idea and not everything has to be classed in OOP. He has since told me that Java or C# don't allow code outside of classes, which sounds a little incredible. Not sure that you can do this in C++, especially when templated functions exist, or generic algorithms. Is it true that this would be bad code for OOP in C++ if I didn't force it into a class?

    Read the article

  • designing classes and objects in .net for a restaurant assignment

    - by Dell Boy
    I have received an assignment at School for creating a Restaurant site. I have to use objects and classes (OOP) for my assignment. I have the foundations of the OOP in .net, but what I don't know is how can I design this assignment to be object-oriented. I don't know how to start it. The requirement is like this: The menu has to be saved in a database and retrieved from it. The menu is devided in appetizers, Salades, Main Meal, Pastas, Wines, Beverages, Extras, Do I create classes like this: Base Class: Menu Derived classes: Appetizers, Salades, Main meal, Pastas, wines, etc. If you have a good example about how to create classes from a Menu that will be great. You don't have to rely on the example I gave above. The menu can be anything. I can deside what the menu will contain. thanks a lot. I am waiting for some help. Please

    Read the article

  • python: how to design a container with elements that must reference their container

    - by Luke404
    (the title is admittedly not that great. Please forgive my English, this is the best I could think of) I'm writing a python script that will manage email domains and their accounts, and I'm also a newby at OOP design. My two (related?) issues are: the Domain class must do special work to add and remove accounts, like adding/removing them to the underlying implementation how to manage operations on accounts that must go through their container To solve the former issue I'd add a factory method to the Domain class that'll build an Account instance in that domain, and a 'remove' (anti-factory?) method to handle deletions. For the latter this seems to me "anti-oop" since what would logically be an operation on an Account (eg, change password) must always reference the containing Domain. Seems to me that I must add to the Account a reference back to the Domain and use that to get data (like the domain name) or call methods on the Domain class. Code example (element uses data from the container) that manages an underlying Vpopmail system: class Account: def __init__(self, name, password, domain): self.name = name self.password = password self.domain = domain def set_password(self, password): os.system('vpasswd %s@%s %s' % (self.name, self.domain.name, password) self.password = password class Domain: def __init__(self, domain_name): self.name = domain_name self.accounts = {} def create_account(self, name, password): os.system('vadduser %s@%s %s' % (name, self.name, password)) account = Account(name, password, self) self.accounts[name] = account def delete_account(self, name): os.system('vdeluser %s@%s' % (name, self.name)) del self.accounts[name] another option would be for Account.set_password to call a Domain method that would do the actual work - sounds equally ugly to me. Also note the duplication of data (account name also as dict key), it sounds logical (account names are "primary key" inside a domain) but accounts need to know their own name.

    Read the article

  • How to make this OO?

    - by John
    Hello, Sorry for the poor title,I'm new to OOP so I don't know what is the term for what I need to do. I have, say, 10 different Objects that inherit one Object.They have different amount and type of class members,but all of them have one property in common - Visible. type TObj1=class(TObject) private a:integer; ...(More members) Visible:Boolean; end; TObj2=class(TObject) private b:String; ...(More members) Visible:Boolean; end; ...(Other 8 objects) For each of them I have a variable. var Obj1:TObj1; Obj2:TObj2; Obj3:TObj3; ....(Other 7 objects) Rule 1: Only one object can be initialized at a time(others have to be freed) to be visible. For this rule I have a global variable var CurrentVisibleObj:TObject; //Because they all inherit TObject Finally there is a procedure that changes visibility. procedure ChangeObjVisibility(newObj:TObject); begin CurrentVisibleObj.Free; //Free the old object CurrentVisibleObj:=newObj; //assign the new object CurrentVisibleObj:= ??? //Create new object CurrentVisibleObj.Visible:=true; //Set visibility to new object end; There is my problem,I don't know how to initialize it,because the derived class is unknown. How do I do this? I simplified the explanation,in the project there are TFrames each having different controls and I have to set visible/not visible the same way(By leaving only one frame initialized). Sorry again for the title,I'm very new to OOP.

    Read the article

  • How do I use a variable within an extended class public variable

    - by Gerry Humphrey
    Have a class that I am using, I am overriding variables in the class to change them to what values I need, but I also not sure if or how to handle an issue. I need to add a key that is generated to each of this URLs before the class calls them. I cannot modify the class file itself. use Theme/Ride class ETicket extends Ride { public $key='US20120303'; // Not in original class public $accessURL1 = 'http://domain.com/keycheck.php?key='.$key; public $accessURL2 = 'http://domain.com/keycheck.php?key='.$key; } I understand that you cannot use a variable in the setting of the public class variables. Just not sure what would be the way to actually do something like this in the proper format. My OOP skills are weak. I admit it. So if someone has a suggestion on where I could read up on it and get a clue, it would be appreciated as well. I guess I need OOP for Dummies. =/

    Read the article

  • How to achieve interaction between GUI class with logic class

    - by volting
    Im new to GUI programming, and haven't done much OOP. Im working on a basic calculator app to help me learn GUI design and to brush up on OOP. I understand that anything GUI related should be kept seperate from the logic, but Im unsure how to implement interaction between logic an GUI classes when needed i.e. basically passing variables back and forth... Im using TKinter and when I pass a tkinter variable to my logic it only seems to hold the string PY_VAR0. def on_equal_btn_click(self): self.entryVariable.set(self.entryVariable.get() + "=") calculator = Calc(self.entryVariable) self.entryVariable.set(calculator.calculate()) Im sure that im probably doing something fundamentally wrong and probabaly really stupid, I spent a considerable amount of time experimenting (and searching for answers online) but Im getting no where. Any help would be appreciated. Thanks, V The Full Program (well just enough to show the structure..) import Tkinter class Gui(Tkinter.Tk): def __init__(self,parent): Tkinter.Tk.__init__(self,parent) self.parent = parent self.initialize() def initialize(self): self.grid() self.create_widgets() """ grid config """ #self.grid_columnconfigure(0,weight=1,pad=0) self.resizable(False, False) def create_widgets(self): """row 0 of grid""" """Create Text Entry Box""" self.entryVariable = Tkinter.StringVar() self.entry = Tkinter.Entry(self,width=30,textvariable=self.entryVariable) self.entry.grid(column=0,row=0, columnspan = 3 ) self.entry.bind("<Return>", self.on_press_enter) """create equal button""" equal_btn = Tkinter.Button(self,text="=",width=4,command=self.on_equal_btn_click) equal_btn.grid(column=3, row=0) """row 1 of grid""" """create number 1 button""" number1_btn = Tkinter.Button(self,text="1",width=8,command=self.on_number1_btn_click) number1_btn.grid(column=0, row=1) . . . def on_equal_btn_click(self): self.entryVariable.set(self.entryVariable.get() + "=") calculator = Calc(self.entryVariable) self.entryVariable.set(calculator.calculate()) class Calc(): def __init__(self, equation): self.equation = equation def calculate(self): #TODO: parse string and calculate... return self.equation if __name__ == "__main__": app = Gui(None) app.title('Calculator') app.mainloop()

    Read the article

  • Could this be considered a well-written PHP5 class?

    - by Ben Dauphinee
    I have been learning OOP principals on my own for a while, and taken a few cracks at writing classes. What I really need to know now is if I am actually using what I have learned correctly, or if I could improve as far as OOP is concerned. I have chopped a massive portion of code out of a class that I have been working on for a while now, and pasted it here. To all you skilled and knowledgeable programmers here I ask: Am I doing it wrong? class acl extends genericAPI{ // -- Copied from genericAPI class protected final function sanityCheck($what, $check, $vars){ switch($check){ case 'set': if(isset($vars[$what])){return(1);}else{return(0);} break; } } // --------------------------------- protected $db = null; protected $dataQuery = null; public function __construct(Zend_Db_Adapter_Abstract $db, $config = array()){ $this->db = $db; if(!empty($config)){$this->config = $config;} } protected function _buildQuery($selectType = null, $vars = array()){ // Removed switches for simplicity sake $this->dataQuery = $this->db->select( )->from( $this->config['table_users'], array('tf' => '(CASE WHEN count(*) > 0 THEN 1 ELSE 0 END)') )->where( $this->config['uidcol'] . ' = ?', $vars['uid'] ); } protected function _sanityRun_acl($sanitycheck, &$vars){ switch($sanitycheck){ case 'uid_set': if(!$this->sanityCheck('uid', 'set', $vars)){ throw new Exception(ERR_ACL_NOUID); } $vars['uid'] = settype($vars['uid'], 'integer'); break; } } private function user($action = null, $vars = array()){ switch($action){ case 'exists': $this->_sanityRun_acl('uid_set', $vars); $this->_buildQuery('user_exists_idcheck', $vars); return($this->db->fetchOne($this->dataQuery->__toString())); break; } } public function user_exists($uid){ return($this->user('exists', array('uid' => $uid))); } } $return = $acl_test->user_exists(1);

    Read the article

  • best PHP programming approach?

    - by Nazmin
    Hello guys, i guess that many of us has acceptable years of experience in PHP programming, me myself got 5 years programming in PHP since in University (not very solid), i just want to gather some suggestion here, what is better approach in PHP OOP? Since there is a lot of PHP framework out there as well as javascript framework, can anyone share their experience in using one of them as well as using both of the PHP and javascript framework together especially for developing enterprise system? (my company want to start using framework, ISP company) if someone has his/her own framework or class or php file so on and so forth, mind to share? now I've only database connection class. I've never use any php framework before, just jquery as javascript framework, my company has a messed up of programming approach because they did not actually a software house, so all the files are scattered across the server, I see that there are some question before about the framework but i just want to know you all approaches on OOP and in developing massive web apps using PHP, or maybe someone kind enough to share their solid written class. Also pro's and con's of all this things. Thanks in advance.

    Read the article

  • Listing all objects that share a common variable in Javascript

    - by ntgCleaner
    I'm not exactly sure how to ask this because I am just learning OOP in Javascript, but here it goes: I am trying to be able to make a call (eventually be able to sort) for all objects with the same variable. Here's an example below: function animal(name, numLegs, option2, option3){ this.name = name; this.numLegs = numLegs; this.option2 = option2; this.option3 = option3; } var human = new animal(Human, 2, example1, example2); var horse = new animal(Horse, 4, example1, example2); var dog = new animal(Dog, 4, example1, example2); Using this example, I would like to be able to do a console.log() and show all animal NAMES that have 4 legs. (Should only show Horse and Dog, of course...) I eventually want to be able to make a drop-down list or a filtered search list with this information. I would do this with php and mySQL but I'm doing this for the sake of learning OOP in javascript. I only ask here because I don't exactly know what to ask. Thank you!

    Read the article

  • Is Polymorphism and Method Overloading is almost the same thing in C++

    - by Maxood
    In C++, there are 2 types of Polymorphism: Object Polymorphism Function Polymorphism Function polymorphism is exactly the same thing as method or function overloading i.e. We use the same method names with different parameters and return types. Now the question is why do we have this fancy name Polymorphism in OOP? What distinctly distinguishes polymorphism from method overloading? Can someone explain with a scenario. Thanks

    Read the article

  • Must Dependency Injection come at the expense of Encapsulation?

    - by urig
    If I understand correctly, the typical mechanism for Dependency Injection is to inject either through a class' constructor or through a public property (member) of the class. This exposes the dependency being injected and violates the OOP principle of encapsulation. Am I correct in identifying this tradeoff? How do you deal with this issue? Please also see my answer to my own question below.

    Read the article

  • Codeigniter Best Practices for Model functions

    - by user270797
    Say my application has a "Posts" model, and one of the function is add_post(), it might be something like: function add_post($data) { $this-db-insert('posts',$data); } Where $data is an array: $data = array ('datetime'='2010-10-10 01:11:11', 'title'='test','body'='testing'); Is this best practice? It means if you use that function you need to know the names of the database fields where as my understanding of OOP is that you shouldnt need to know how the method works etc etc

    Read the article

  • Which PHP CMS has the best architecture?

    - by Peter Bailey
    In your opinion, which PHP CMS has the best architecture? I don't care about how easy its admin panel is to use, or how many CMS features it has. Right now, I'm after how good its code is (so, please, don't even mention Drupal or Wordpress /shudder). I want to know which ones have a good, solid, OOP codebase. Please provide as much detail as you can in your replies.

    Read the article

  • Access modifiers in Object-Oriented Programming

    - by Imran
    I don't understand Access Modifiers in OOP. Why do we make for example in Java instance variables private and then use public getter and setter methods to access them? I mean what's the reasoning/logic behind this? You still get to the instance variable but why use setter and getter methods when you can just make your variables public? please excuse my ignorance as I am simply trying to understand why? Thank you in advance. ;-)

    Read the article

  • how does object programming work?

    - by venom
    Hello, I am not sure about some things in oop. If I have Class1, which has some private field, for example private Field field1, and make getField1(){return field1;} then I have some class with constructor public Class2(Field field){someMethod(field);} And then I call constructor of Class2 in Class3 like: Class2 cl = new Class2(instanceOfClass1.getField1()); And now the question: Am I working with field1 of instanceOfClass1 in "someMethod(field)"?

    Read the article

  • C# Creating A Error Checking Class?

    - by Soo
    Hi StackOverflow, I'm very new to OOP, and in the program I'm working on, I have an Utilities class that contains some general methods. Should I include my error checking in the Utilities class or should I create a new class just for error checking?

    Read the article

  • What are the reasons to select Object Oriented Programming over Procedural Programming?

    - by Starx
    Nowadays, Standard Coding has become Synonymous to Object Oriented Programming. But what are the reasons that forced classical procedural programming out of the way and rose the new concept of Object Oriented Programming. What were the limitations that Procedural Programming could not accomplish? and Does procedural language still hold some value in the field of programming? If yes, What are they, and What are there advantages over OOP?

    Read the article

  • Writing SDK documentation, need useful beginner tutorials

    - by David Rutten
    I'm currently writing SDK documentation for one of our products, but for obvious reasons I don't want to talk about the essentials of OOP. Does anyone know any good online teaching material that explain (aimed at absolute beginners) concepts such as classes, inheritance, constructors, instances etc.? Preferably urls that are likely to survive for a couple of years to come... It's a DotNET SDK and we're including only VB and C# samples, so C++ or Delphi or Lisp material is not that useful.

    Read the article

  • What are possible designs for the DCI architecture?

    - by Gabriel Šcerbák
    What are possibles designs for implementation of the DCI (data, contexts, interactions) architecture in different OOP languages? I thought of Policy based design (Andrei Alexandrescu) for C++, DI and AOP for Java. However, I also thought about using State design pattern for representing roles and some sort of Template method for the interactions... What are the other possibilities?

    Read the article

< Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >