encapsulation
All posts containing the 'encapsulation' tag
We’re here! To now, we’ve come through part 1, part 2, part 3, and part 4, and now we’re ready to wrap it up. So, without further ado, the conclusion to the Field encapsulation pattern!
Where are we?
At this point, we have field objects, we have validation functions, have required, we have read-only. What’s left? Flashing back to the requirements, we need a serializable representation and a default value. Let’s throw those in!
Serialization fun
I use json. A lot. It’s cross-platform, easy (enough) to read, has far less bloat than XML, and...
READ MORE
Here we are in the fourth portion of our trek to create a field encapsulation pattern in Python! For previous legs of our journey, you can try here, here, or here. Otherwise, let’s kick it off!
Where are we?
By the end of our last meeting, we had made pretty good progress. We’re able to type fields on an object, mark them as required so we must provide their values when creating said object, and mark attributes as read-only so we can’t change them after the object has been created.
But, before we go any further...
READ MORE
Welcome back to creating a field encapsulation pattern in Python! As you may be aware, this is the third installment in the series. To catch up, you can read part 1 and part 2; I’ll wait. Ready? Let’s go!
Where are we?
First, let’s review the requirements for this project:
- Type safety: we need to be sure that an attribute is of a defined type
- Required: we need some attributes while others are optional
- Read Only: certain attributes should be read-only
- Serialized representation: during serialization, we need to convert the unserializable value to one which can...
READ MORE
Some background
At work, we’re currently spooling up more and more Python, which I think is great! I love working with Python. However, with this shift, we’re moving away from an ORM framework in PHP which had things like attribute validation, and we’re not using one in Python which does the same. So, now I’m up against validating in a dynamically typed language efficiently and with the least amount of code possible. The thing with a dynamically typed language is that you can assign whatever value you want to whatever variable you want; if I want attributes of this...
READ MORE