oop

optional arguments in initializer of python class

为君一笑 提交于 2021-01-18 05:14:40
问题 I was wondering if anyone had any good ways of quickly explaining how to efficiently and pythonically create user defined objects with optional arguments. For instance, I want to create this object: class Object: def __init__(self, some_other_object, i, *j, *k): self.some_other_object = some_other_object self.i = i # If j is specified, assume it is = i if(j==None): self.j = i else: self.j = j # If k is given, assume 0 if(k==None): self.k = 0 else: self.k = k Is there a better way to do this?

When do I keep a map<Identifier, Object> vs a Collection<Object with identifier as field>

不羁岁月 提交于 2021-01-08 02:04:15
问题 There is one question that I often ask myself while designing a program, and I am never quite sure how to answer it. Let's say I have an object with multiple fields, amongst which there is one serving as the identifier to that specific object. Let's also say that I need to keep track of a List of such objects somewhere else. I now have three, and probably even more, options on how to go about it: Have my object contain its own identifier, and all its other fields. I now use a simple array (or

When do I keep a map<Identifier, Object> vs a Collection<Object with identifier as field>

回眸只為那壹抹淺笑 提交于 2021-01-08 02:01:27
问题 There is one question that I often ask myself while designing a program, and I am never quite sure how to answer it. Let's say I have an object with multiple fields, amongst which there is one serving as the identifier to that specific object. Let's also say that I need to keep track of a List of such objects somewhere else. I now have three, and probably even more, options on how to go about it: Have my object contain its own identifier, and all its other fields. I now use a simple array (or

When do I keep a map<Identifier, Object> vs a Collection<Object with identifier as field>

ε祈祈猫儿з 提交于 2021-01-08 02:01:24
问题 There is one question that I often ask myself while designing a program, and I am never quite sure how to answer it. Let's say I have an object with multiple fields, amongst which there is one serving as the identifier to that specific object. Let's also say that I need to keep track of a List of such objects somewhere else. I now have three, and probably even more, options on how to go about it: Have my object contain its own identifier, and all its other fields. I now use a simple array (or

When do I keep a map<Identifier, Object> vs a Collection<Object with identifier as field>

懵懂的女人 提交于 2021-01-08 02:01:15
问题 There is one question that I often ask myself while designing a program, and I am never quite sure how to answer it. Let's say I have an object with multiple fields, amongst which there is one serving as the identifier to that specific object. Let's also say that I need to keep track of a List of such objects somewhere else. I now have three, and probably even more, options on how to go about it: Have my object contain its own identifier, and all its other fields. I now use a simple array (or

C++: Can a class has an object of it's own type?

旧时模样 提交于 2021-01-05 04:52:37
问题 I am trying to solve the Conway's game of life in c++. So according to my design, I have a cell class which contains a list of 8 neighbours, which itself is an object of type cell. Is it ok to do that. The code looks like this class Cell { private: int position_row_; int position_colm_; std::shared_ptr<State> state_; std::vector<Cell> neighbours_; }; Now, the other question that is bugging me is, what type of relationship is it. While designing i thought of it to be 'Aggregation'; but now i

C++: Can a class has an object of it's own type?

情到浓时终转凉″ 提交于 2021-01-05 04:45:33
问题 I am trying to solve the Conway's game of life in c++. So according to my design, I have a cell class which contains a list of 8 neighbours, which itself is an object of type cell. Is it ok to do that. The code looks like this class Cell { private: int position_row_; int position_colm_; std::shared_ptr<State> state_; std::vector<Cell> neighbours_; }; Now, the other question that is bugging me is, what type of relationship is it. While designing i thought of it to be 'Aggregation'; but now i

Python: Tkinter: Why is it root.mainloop() and not app.mainloop()

末鹿安然 提交于 2020-12-30 02:40:07
问题 I'm a new member to Stack Overflow. I found this thread, but was not allowed to comment or ask questions on it, so I thought I'd just reference it here: How can I make a in interactive list in Python's Tkinter complete with buttons that can edit those listings? from tkinter import * import os import easygui as eg class App: def __init__(self, master): frame = Frame(master) frame.pack() # character box Label(frame, text = "Characters Editor").grid(row = 0, column = 0, rowspan = 1, columnspan =

Python - When to create a Class and when to create a Function

时间秒杀一切 提交于 2020-12-29 13:12:50
问题 Right, so I'm trying to create a Contacts application using Python OOP. I'm fairly new to OOP and still trying to get my head around the concepts. I understand that a Class is a blueprint for all objects. I like to think of a Class as an entity and each Object is a record of that entity. I am from a Database background so that's why I interpret it like this, feel free to correct me. Anyways, in the Contacts app I'm making I've created the Class Contacts as outlined below: class Contacts():

Python - When to create a Class and when to create a Function

此生再无相见时 提交于 2020-12-29 13:10:03
问题 Right, so I'm trying to create a Contacts application using Python OOP. I'm fairly new to OOP and still trying to get my head around the concepts. I understand that a Class is a blueprint for all objects. I like to think of a Class as an entity and each Object is a record of that entity. I am from a Database background so that's why I interpret it like this, feel free to correct me. Anyways, in the Contacts app I'm making I've created the Class Contacts as outlined below: class Contacts():