Please help with this program
dimanche 21 février 2021
Extract a string between two set of patterns in Python
I am trying to extract a substring between two set of patterns using re.search().
On the left, there can be either 0x or 0X, and on the right there can be either U, , or \n. The result should not contain boundary patterns. For example, 0x1234U should result in 1234.
I tried with the following search pattern: (0x|0X)(.*)(U| |\n), but it includes the left and right patterns in the result.
What would be the correct search pattern?
design patterns for travel system
I have a small python project to work with 3 design patterns.
my idea is a travel book system (flight, train, bus) -> hier I tried to use the stratgy pattern to choise which way of travel (I'm not sure if that's right)
- the user can book a place depens on the travel-type
- the status of the trip can be changed from (availble - lated - canceled ) I tried to use State pattern
can you please help by implemnt an python example and correct me if i choised wrong design patterns.
thanks
Design a system of classes to filter messages at runtime in a Spring boot JMS app
I have a Springboot JMS application in which I have a class that is a component and receives messages from a JMS Queue/Topic since it implements the JMSLIstener Interface. My requirement is to have a design so that I can filter messages received like whether it is in XML or Json or plain text and have the specific Message processing class called to process the Message for further use.
Any sort of performance design ideas or system design ideas appreciated as I am new to system design.
vendredi 19 février 2021
Python OOP Design Pattern for Calculation Flows
I am relatively new to oop and had a quick question about the best way to approach coding a certain type of calculation. I'm curious if there's an established design pattern to approach this sort of problem.
Consider a chemical process flow where you convert materials (a,b) with attributes such as temperature, pressure, flow rate, etc. into a final product c. To get there, I need unit operations D,E,F... each with its own set of attributes (cost, size, etc.). I would only need information flow in one direction as closed loops will probably increase the complexity (if not, I would really appreciate insight into how closed loops would work).
a,b --> D --> E --> F --> c
Ultimately I would like to be able to do a system cost analysis, where I would sum up the cost attributes of D,E,F.
My current thought process to approach this is to define a "materials" object, then have D inherit materials, E inherit D... c inherit F then lastly a "system" object inherit c to analyze the system variables. Since I would like to be able to swap out D,E,F for say G,H,I, there also needs to be code for conditional inheritance where D must be able to accept inputs a,b (based on defined attributes) and E be able to inherit D for the same reason. One of the things I'm unsure of is how object c would be able to understand how to sum up attributes of all the inherited objects (probably based on some consistent naming convention of objects/attributes?).
Sorry for the somewhat lengthy question - if you are aware of AspenPlus, I'm looking to replicate a smaller scale version of this (ie no solvers) in Python. Thank you for reading through this!
Are you searching for a logo designer to create animal and pet logo?
This is a graphic designing team of professionals who are enthusiast to design amazing product branding. Working in this industry since past 4 years and always target to deliver some extraordinary product.
visit the link and contact : Click Now
How to design API to persistence layer?
Imagine the situation. There's a table with say 20 fields, like:
| n/n | name |
|-----|------|
| 0 | id |
| 1 | foo |
| 2 | bar |
| ... | ... |
| 20 | baz |
and you need to design CRUD API for it. There's nothing complicated with create() and delete() methods, but update(..) and find(...) are real pain.
From UI perspective user can change or request a search by any of those fields and in any combination: update(foo=x, baz=y) or find(foo=x, bar<=y).
There are two pattern for DAL: Repository and DAO.
-
Repository says "threat API like a collection of objects", so it's usually looks like that:
Repository { replace(Pojo o) find(PojoSpec spec) }find()is ok, but usingreplace(Pojo o)means that we lose info about what fields has been actually changed. We have to either update the whole object or select-compare-update only changed fields (so +1 request, please don't tell about premature optimization, it's an API design question). Both options are sub-optimal, because DB also doesn't care about comparing values. It just rewrites all fields specified in the SQL query. What if table has 100 fields? 200? Would you rewrite 100 fields if just one of them has been changed? -
DAO is not really a pattern, it's just some persistence-oriented code around domain object with no real restrictions. So, API like
findByFooAndBarAndBaz()is quite usual. It also doesn't solveupdate()problem though.
So, what's left? We could just pass changed fields as key-value pairs, but it's ugly and not type safe: replace(Map<String, Object> o). Type-safety can be fixed buy creating a metamodel, but exposing metamodel classes to services layer looks like sort of code smell.
The question is: what is the common approach to handle situations like that? Are there another DAL patterns? Am I right about metamodel code smell?