preface
Short step without thousands of miles, not small streams into rivers and seas. Learning is like rowing upstream; not to advance is to drop back. I’m a hauler who drifts from platform to platform. Today I’m going to talk about some interview questions about design patterns. Nonsense not to say, directly to everyone dry goods, I hope to help you, excellent people have been praised.
Six design principles in programming?
1. Principle of single responsibility
In layman’s terms, a class does only one thing
-
CALayer: Display of animations and views.
-
UIView: only responsible for event passing and event response.
2. Open and close principle
Closed for modifications, open for extensions.
Consider future extensibility rather than going back and forth
3. Interface isolation principle
Use multiple specialized protocols rather than one bloated protocol
-
UITableviewDelegate
-
UITableViewDataSource
4. Dependency inversion principle
Abstraction should not depend on concrete implementation, concrete implementation can depend on abstraction.
The calling interface doesn’t feel what’s going on inside
5. Richter’s substitution principle
A parent class can be seamlessly replaced by a subclass without affecting its functionality
Such as KVO
Demeter’s Rule
One object should know as little as possible about the other, achieving high aggregation and low coupling
How to design a picture caching framework?
This can be done by mimicking SDWebImage.
-
Manager
-
Memory cache
-
Disk cache
-
Internet downloads
-
Code Manager
-
Image decoding
-
Image decompression
-
The image is stored with the hash value of the image as the Key
Memory design needs to consider the Size of storage because of the limited memory space, we provide different schemes for different sizes of pictures
-
50 under 10K
-
20 under 100Kb
-
10 with a size greater than 100kb
Elimination strategy
There are three times when LRU (least Recently used algorithm) triggers the elimination strategy of memory
-
1. Regular inspection (not recommended, consumption of performance)
-
2. Increase check trigger frequency (be careful about overhead)
-
1. Switching between front and back
-
2. Every time you read or write
-
Disk design considerations
-
storage
-
Size limits (there are fixed sizes)
-
Removal policy (can be set to 7 or 15 days)
Network design considerations
-
Maximum number of concurrent image requests
-
Request Timeout Policy
-
Request priority
Image decoding
Apply policy mode to decode different image formats such as JPG, PNG and GIF
The timing of the image decoding
-
When the child thread image has just finished downloading
-
When the child thread has just finished reading from disk
Avoid decompression and decoding in the main thread to avoid stalling
3. How to design a statistical framework for time
recorder
-
Page type recorder
-
Flow recorder
-
The custom type
Record manager
-
Memory record cache
-
Disk storage
-
uploader
How to reduce the loss rate of data?
-
Periodically Writing data to disk
-
Whenever a certain value is reached, it is written to disk
Record the timing of the upload
-
You can upload it while switching between front and back
-
Uploads can be uploaded when switching from netless to netted
Selection of upload timing
-
Immediately upload
-
Time to upload
-
Delay to upload
conclusion
Today’s interview to share here, I hope to see you can have a little help. Next time I’ll break it down.
What encryption methods are used in SSL encryption and why?
RSA asymmetric encryption
RSA encryption? How does RSA Encryption work?Copy the code